Here are the 3 components to these statements:
expression- The body of the loop. The results of this expression get inserted into the array that is being created.
for eachloop - The
variablegets assigned the property values (
for each) or property names (
for/in) of the
objectmay be a generator, iterable object, or an array. There is an implied
letkeyword before the variable (the
letkeywords are not allowed before the variable name). The variable used in the array comprehension is not visible outside the square brackets and does not overwrite variables by the same name.
if (condition)(optional) - Used to filter iterated values.
touchdowns = [1,2,3]; points = [x*7 for each (x in touchdowns)]; //creates new points array