Массив. Массив — это объект особого типа, подходящий для хранения упорядоченных элементов данных и управления ими. let arr = [item1, item2...];
Фильтр. Метод filter() создает массив, заполненный всеми элементами массива, прошедшими проверку (предоставляется как функция).
Карта. Карта – это набор элементов, каждый из которых хранится в виде пары "ключ-значение".
Reduce: метод reduce () уменьшает массив до одного значения.
forEach: метод forEach() вызывает функцию один раз для каждого элемента массива по порядку.
Давайте посмотрим на замечательный пример связанных тем:
var products = [ {id : 101, name : 'Kerry', cost : 50, units : 20, category : 'stationary'}, {id : 108, name : 'Ten', cost : 70, units : 70, category : 'stationary'}, {id : 103, name : 'Safari', cost : 60, units : 60, category : 'grocery'}, {id : 105, name : 'Zen', cost : 30, units : 30, category : 'grocery'}, {id : 111, name : 'Honda', cost : 20, units : 80, category : 'utencil'}, ]; Array methods: filter forEach map reduce 1. find out all the stationary products const staionaryProducts = products.filter(product => product.category === 'stationary'); 2. find out the maximum cost from the product list const maxCost = products.reduce((result, product) => result > product.cost ? result : product.cost, 0); 3. create a new array of products where the cost is discounted by 10% const discountedProducts = products.map(product => ({...product, cost : product.cost * 0.9})); 4. find the sum of units const totalUnits = products.reduce((result, product) => result + product.units, 0); 5. print the following for each product We have 20 units of pen at Rs.50 each products.forEach( ({units, name, cost}) => console.log(`We have ${units} units of ${name} at Rs.${cost} each`));