If we have a person's name in a string, e.g. Jon Smith, we can find the first and last names using the split function:
var name = 'Jon Smith'; var parts = name.split(' '); alert('Your first name is: ' + parts); alert('Your last name is: ' + parts);
The result is:
We passed a space character, i.e. ' ', to the split function, and it broke up the string wherever it found the character. The value returned was an array.