0
String concatenate loop in JavaScript
How can I create the function which collect the strings inside an array to concatenate together? Such as get the word animations from this array arr = [ an,im,at,io,ns]. Please help me and thank for all your advices.
3 ответов
+ 4
You could loop through the array printing each element or you could loop through the array and add each element to a string.
To add them to a string do somthing like
myString+=myArray[using for loop as index];
+ 1
You can also make use of array reduce method.
let arr = ["an","im","at","io","ns"];
let c=arr.reduce((a,b)=>{
return a+b;
})
console.log(c);