Loops enable repeated execution of code; the for-of loop iterates over array elements by assigning each element to a loop variable and running the loop body for each assignment. The loop body is the code block in curly braces and one execution of that block is called an iteration. The array method .push() appends a value to the end of an array and increases its length. A common processing pattern creates an empty output array, loops over the input, and pushes transformed elements to the output per iteration. The array method .join() concatenates array strings into a single string using a separator.
Loops are JavaScript statements that execute the same piece of code zero or more times. The most popular loop is for-of: The code block (in curly braces) that starts at the end of line A is called the body of the loop. This loop iterates over the array arr: First it assigns arr[0] to elem and runs the body. Then it assigns arr[1] to elem and runs the body. One execution of the body is called a loop iteration.
The array method .push() appends a value to the end of an array - thereby increasing its length by one: Processing an array via array.push() and a loop # One common technique for processing an array is: The output array is initially empty. We loop over the input array. Per iteration, we push zero or more elements to the output array.
Collection
[
|
...
]