Iterators

Reduce

// gets the sum of all values

let arr = [2,5,7,8,23,100];
let acc = 0;
let currentValue = 0;


const sum = arr.reduce((acc, currentValue) => acc + currentValue);

console.log(sum);

ForEach

// loops through each element and does something

const numbers = [28, 77, 45, 99, 27];
 
numbers.forEach(number => console.log(number));

Filter

// only if parameter is true is value appended to the filtered array

const randomNumbers = [4, 11, 42, 14, 39];

const filteredArray = randomNumbers.filter(n => n > 5);

Map

// does something to the element and adds it to an new array

const arr = [2, 5, 2, 5, 6];

const newArr = arr.map(n => n + 8);