const name = ['John Doe', 'Jack Lock', 'Nick Load'];
const initials = name.map([a]) => a);
console.log(initials);
I'm trying to print array items initials, but I only got first letter of the items.
What I need
['J.D', 'J.L', 'N.L']
map() to loop over the arraysplit() to get first and last namemap() again over both namessubstring() to get the first charjoin() to concat againconst name = ['John Doe', 'Jack Lock', 'Nick Load'];
const initials = name.map(n => n.split(' ').map(s => s.substring(0, 1)).join('.'));
console.log(initials);
[
"J.D",
"J.L",
"N.L"
]
pin any of those names ;)