We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
let initials = ''; if (person.name) { initials = person.name.trim().split(' '); if (initials.length > 1) { initials = `${initials[0][0]}${initials[1][0]}`; } else if (initials.length === 1) { initials = initials[0][0]; } }
The text was updated successfully, but these errors were encountered:
Accounted for hyphenated last names
function nameInitials(person){ let initials = ''; if (person.name) { initials = person.name.trim().split(/[ -]/); if (initials.length > 2) { initials = `${initials[0][0]}${initials[1][0]}${initials[2][0]}`; return initials } else if(initials.length > 1) { initials = `${initials[0][0]}${initials[1][0]}`; return initials }else if (initials.length === 1) { initials = initials[0][0]; return initials } } } nameInitials({name: "test tester-son"})
Sorry, something went wrong.
Another method:
let initials = fullName.split(/[ -]/).map((n) => n.charAt(0)).join('');
No branches or pull requests
The text was updated successfully, but these errors were encountered: