I am struggling a bit with this problem.
I have a string "Jan van Wyk". "Jan" is the firstname and "van Wyk" is the lastname.
let enqBy = "Jan van Wyk";
var firstName = enqBy.split(' ').slice(0, -1).join(' ');
var lastName = enqBy.split(' ').slice(-1).join(' ');
console.log(firstName);
console.log(lastName);
Using this code the result is firstname = "Jan van"
and lastname = "Wyk"
which is not what I want.
If I have a string like "Elvis Presly" the code works perfectly firstname = "Elvis"
and lastname = "Presley"
.
Please guide me.
Via Active questions tagged javascript - Stack Overflow https://ift.tt/mPxjc1u
Comments
Post a Comment