All about arrays
Arrays are lists lists of of data.
Array.prototype.forEach()
The forEach array method takes a callback function as a
parameter, and will run the callback on each item of the array.
Array.prototype.map()
The map array method takes callback function which runs on
each item in the array, and will create a new array.
Array.prototype.reduce()
The reduce array method takes callback function which runs on
each item in the array, and will a single value.
The callback function takes two parameters
(previousValue, currentValue). In addition to a callback
function, the reduce method also takes a parameter for
initial value.
reduce(callbackFunction, startValue)
Challenge 1
Solution 1
Challenge 2
Solution 2
xxxxxxxxxx14
/*** Challenge 1* Use the 'reduce' method to calculate total from cartItems*/const cartItems = [ { name: 'Shoes', price: 67 }, { name: 'Hat', price: 24 }, { name: 'Socks', price: 15 },]// const total = cartItems.reduce(???)console.log(total)press 'run' to view console output