Answers for "display only initials from full name reactjs"

0

display only initials from full name reactjs

var getInitials = function (string) {
    var names = string.split(' '),
        initials = names[0].substring(0, 1).toUpperCase();
    
    if (names.length > 1) {
        initials += names[names.length - 1].substring(0, 1).toUpperCase();
    }
    return initials;
};

console.log(getInitials('FirstName LastName'));
console.log(getInitials('FirstName MiddleName LastName'));
console.log(getInitials('1stName 2ndName 3rdName 4thName 5thName'));
Posted by: Guest on March-23-2021

Code answers related to "display only initials from full name reactjs"

Code answers related to "Javascript"

Browse Popular Code Answers by Language