String concatenate loop in JavaScript | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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.

8th Feb 2021, 8:03 AM
Lin Huang
Lin Huang - avatar
3 Answers
+ 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];
8th Feb 2021, 8:14 AM
D_Stark
D_Stark - avatar
+ 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);
8th Feb 2021, 8:35 AM
Abhay
Abhay - avatar