I'm quite new in coding, so might be an easy question for you all. What exactly should I do if I have this array and want to just show the first letter of every element of it?
var friends = ["John", "Will", "Mike"];
I wanted to do it with substr
method but I just want to know how to do it with a string.
Use Array.map()
to iterate the array, take the 1st letter using destructuring, and return it:
const friends = ["John", "Will", "Mike"];
const result = friends.map(([v])=> v);
console.log(result);