How do I use forEach to turn an array of strings into a single string
You can't use forEach
on strings
. forEach
is meant to be used with arrays
You can make use of join
here to join an array.
let words = [
'Loops',
'are',
'a',
'great',
'way',
'to',
'find',
'elements',
'in',
'an',
'array',
];
function createParagraph(words) {
return words.join(' ');
}
console.log(createParagraph(words));