Forum Moderators: open
name = "Julio Gonzalez Escondido de la Rosa";
nameArray = name.split(" "); // Turns the name into array, with each word as a separate element
lastName = nameArray[nameArray.length-1];
alert(lastName); // Test to make sure it works
--------------
The reason you subtract 1 is that the array elements are numbered starting at 0 (0, 1, 2, 3, 4, 5), but the length is the number of items in the array (6).
The other solution is to capture the last name separately from the first name when you're gathering your input in the first place. If the user is filling out a form, have two fields, one for first name and one for last name. That way you can refer to them separately.