For example:
Someone uses their full name in one field instead of first and last in separate fields. If you then want to split it and define the first word (name) as the first name and any other words in that field as the last name, you can do that using some JavaScript code.
Option 1
First name’s the same no matter what, so we can define it here
var firstname = nameArrr0]
var lastname
Check if there’s more than 2 elements in the array (i.e. a middle or multi-stage name)
if(nameArr.length > 2){
Remove the first item in the array
nameArr.shift()
Then join that modified array up with a space in between the elements
lastname = nameArr.join(" ")
} else {
But if there’s less than two (i.e normal name) then return the last name as you were
lastname = nameArranameArr.length - 1]
}
output = p{firstname, lastname}];
Option 2
Here is another alternative:
var fullName = input.name.split(' ');
var firstName = fullName.shift();
var lastName = fullName.join(' ');
output = p{firstname: firstName, lastname: lastName}];
Anyone have any other creative ways of getting the same result?