Answers for "11.7.1. Joining Array Elements With a Loop // Functions"

0

11.7.1. Joining Array Elements With a Loop // Functions

/*Use a for loop to iterate through the array and add each entry into 
the newString variable.*/

let arr = ['L', 'C', '1', '0', '1'];
let newString = '';

for (i = 0; i < arr.length; i++){
   newString = newString + arr[i];
}

console.log(newString);
console.log(arr);

'LC101'
['L', 'C', '1', '0', '1']
Posted by: Guest on July-16-2021
0

11.7.1. Joining Array Elements With a Loop // Functions

/*Use a while loop to add the first element in the array to newString, 
then remove that element from the array.*/

let arr = ['L', 'C', '1', '0', '1'];
let newString = '';

while (arr.length > 0){
   newString += arr[0];
   arr.shift();
}
console.log(newString);
console.log(arr);

'LC101'
[ ]
Posted by: Guest on July-16-2021

Code answers related to "11.7.1. Joining Array Elements With a Loop // Functions"

Code answers related to "Javascript"

Browse Popular Code Answers by Language