You should use the String.prototype.split()
method:
'Paul Steve Panakkal'.split(' '); // returns ["Paul", "Steve", "Panakkal"]
You can use it this way:
'Paul Steve Panakkal'.split(' ').slice(0, -1).join(' '); // returns "Paul Steve"
'Paul Steve Panakkal'.split(' ').slice(-1).join(' '); // returns "Panakkal"
So in common:
var firstName = fullName.split(' ').slice(0, -1).join(' ');
var lastName = fullName.split(' ').slice(-1).join(' ');
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…