showing results for - "display only initials from full name reactjs"
Cristina
11 Nov 2017
1var getInitials = function (string) {
2    var names = string.split(' '),
3        initials = names[0].substring(0, 1).toUpperCase();
4    
5    if (names.length > 1) {
6        initials += names[names.length - 1].substring(0, 1).toUpperCase();
7    }
8    return initials;
9};
10
11console.log(getInitials('FirstName LastName'));
12console.log(getInitials('FirstName MiddleName LastName'));
13console.log(getInitials('1stName 2ndName 3rdName 4thName 5thName'));