Home > Mobile >  i want to write a function that return first name and first index of second name, i can use the slic
i want to write a function that return first name and first index of second name, i can use the slic

Time:04-20

function returnName(Aname) {
  return // first name and only first charctars of seconed name
}

console.log(returnName(`Ali Ahmad`)); // Ali A 

CodePudding user response:

You can use:

function returnName(name) {
  const [f,s] = name.split(' ')
  return `${f} ${s.charAt(0)}`
}

console.log(returnName(`Ali Ahmad`));
  • Related