Answers for "get initials from full name javascript"

3

js get initials from name

const fullName = nameString.split(' ');
const initials = fullName.shift().charAt(0) + fullName.pop().charAt(0);
return initials.toUpperCase();
Posted by: Guest on May-12-2020
0

get initials from full name javascript

const fullName1 = "Noah William";
const fullName2 = "Jackson";

const getInitials = (name) => {
  let initials = name.split(' ');
  
  if(initials.length > 1) {
    initials = initials.shift().charAt(0) + initials.pop().charAt(0);
  } else {
    initials = name.substring(0, 2);
  }
  
  return initials.toUpperCase();
}

console.log(getInitials(fullName1)) // NW
console.log(getInitials(fullName2)) // JA
Posted by: Guest on May-07-2021

Code answers related to "get initials from full name javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language