I am working on my first javascript assignment and we have been asked to “Write a function that takes an Array of strings as an argument and prints the first letter of each element out (one per line)” however we must use a FOR OF loop, function, and charAt() the output should be
H
W
T
I
M
S each letter on its own line
I am struggling because I only know how to complete the task by using the toString.charAt method but that is not what the assignment asked for. I also am not sure if the for of loop goes in the function or the function goes in the loop. Just started JS last week very confused. Please help.
let arr = (["Hello", "World", "This", "Is", "My", "String"]);
// required for of
for (let element of arr) {
console.log(element.toString())
}
// required function
let myFunction = (element) => element.charAt(0);
myFunction(arr)
// required charAt
var str = new String( "This is string" );
console.log( arr.toString().charAt(0));
console.log( arr.toString().charAt(6));
console.log( arr.toString().charAt(12));
console.log( arr.toString().charAt(17));
console.log( arr.toString().charAt(20));
console.log( arr.toString().charAt(23));