I have this var fullName = 'Muhammad Ali'
, what I want to do is split the First Name and Last name from it.
CodePudding user response:
For simple cases, use .split()
. Usually a simple google search can help you.
let fullName = 'Muhammad Ali'
let formattedName = fullName.split(" ")
console.log(formattedName)
CodePudding user response:
You can use the .split() method to split the string to an array based on spaces in the string. I would use caution with this as names can differ in length and have more than one space.