Lesson 3 of 4
Arrays and Loops
An array is an ordered list of values:
for...of
for...of visits every item in an array:
The classic counting loop works too:
filter and map
Arrays have built-in methods that take a function. filter keeps items that pass a test, and map transforms each item:
Exercise: Only the evens
Write evens(numbers) that returns a new array with only the even numbers, in their original order.
Your turn!
Write your code in and press Submit answer.
- console.log(JSON.stringify(evens([1, 2, 3, 4]))); → [2,4]
- console.log(JSON.stringify(evens([7, 9]))); → []
- plus 1 hidden check