11 7 1 joining array elements with a loop 2f 2f functions

Solutions on MaxInterview for 11 7 1 joining array elements with a loop 2f 2f functions by the best coders in the world

showing results for - "11 7 1 joining array elements with a loop 2f 2f functions"
Chrystal
11 Jan 2019
1/*Use a for loop to iterate through the array and add each entry into 
2the newString variable.*/
3
4let arr = ['L', 'C', '1', '0', '1'];
5let newString = '';
6
7for (i = 0; i < arr.length; i++){
8   newString = newString + arr[i];
9}
10
11console.log(newString);
12console.log(arr);
13
14'LC101'
15['L', 'C', '1', '0', '1']
Cristóbal
18 Sep 2019
1/*Use a while loop to add the first element in the array to newString, 
2then remove that element from the array.*/
3
4let arr = ['L', 'C', '1', '0', '1'];
5let newString = '';
6
7while (arr.length > 0){
8   newString += arr[0];
9   arr.shift();
10}
11console.log(newString);
12console.log(arr);
13
14'LC101'
15[ ]