Skip to content

Instantly share code, notes, and snippets.

@alexko30
Created April 30, 2018 22:33
Show Gist options
  • Save alexko30/4455bbef5c577735fc0b6791925f5fb0 to your computer and use it in GitHub Desktop.
Save alexko30/4455bbef5c577735fc0b6791925f5fb0 to your computer and use it in GitHub Desktop.
make Initials From Name
function makeInitialsFromName(strName) {
const arrName = strName.split('');
const firstLetter = strName.charAt(0).toUpperCase();
let arrInitials = [];
arrInitials.splice(0, 0, firstLetter, '. ')
for (var i = 0; i < arrName.length; i++) {
if (arrName[i] == ' ') {
const secondLetter = arrName[i + 1].toUpperCase();
arrInitials.splice(0, 0, secondLetter, '.');
const initials = arrInitials.toString().replace(/,/g, '');
console.log(initials);
}
}
}
makeInitialsFromName('alex ko');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment