get initials from full name javascript

const fullName = nameString.split(' ');
const initials = fullName.shift().charAt(0) + fullName.pop().charAt(0);
return initials.toUpperCase();

3.78
9
Awgiedawgie 440215 points

                                    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

3.78 (9 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
getting name initials using js take only initials of name js javascript name initials how to return only the initials in a name javascript javascript extract initials from name How get initials from name in javascript get initials javascript get initials from full name javascript function to identify initials from a name js get initials js javascript get initials from name real time get first character of name and sername in js js get initials from string get first initial javascript javascript get user initials take initial from name jquery how to get initial javascript get initials getting the first initials in an array in javascript javascript function get initials generate code from first letters of given name javascript javascript shorten name and give full name by that short nam how to get name first intial in javascript get name initials javascript how to show names with only the first letter of the lastname react get initials of name typescript how to get initials from name in javascript how to take the first letter of fullname in js javascript first letter of first name and last name find initials in javascript with split.() initials javascript reduce fullname to initials get initials regex javascript strip out initials from name javascript typescript get initials from name get the first initals of full name in lodash convert fullname into initials in javascript getting starting letter in name in js take first initial javascript js extract initials get initials of name javascript getinitials in lodash get firstname and lastname intials from string in lodash get first initial name typescript how to get initials for firstname and lastname in vuejs jquery get intials from name javascript get intials from name return initials javascript get initials in javascript how to print initials of words from array javascript how to print word initials like a.k in javascript get only name initials letters js getInitials js get the first letter of first name and last name in javascript create initials from a username js get initals only of word js display initials with last name javascript javascript get the first and last letter of first and last name get first nad last letter initial js js initials from name initials string js display initials in javascript display initials with last name in the middle in javascript how to get only initials in javascript get initials javascript function javascript get initials from full name javascript get initials from name javascript get initials function turn name into intial javascript get initials from name javascript js get initials from name
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source