JSFiddle - React, Tailwind, and code Playground
by Alex Baumgertner
JavaScript
var arrayToReduce = [{
"productID": "5505d8e0688c74a404340f9a",
"quantity": 2,
"price": 696,
"image": "http://lorempixel.com/640/480/technics",
"header": "Switchable 24/7 internet solution",
"theme": "doloribus id beatae sunt dicta ut",
"title": null
}, {
"productID": "5505d8e0688c74a404340f9c",
"quantity": 1,
"price": 710,
"image": "http://lorempixel.com/640/480/technics",
"header": "Balanced logistical help-desk",
"theme": "rem quaerat qui illum",
"title": null
}];
var totalPrice = arrayToReduce.reduce(function (previousValue, currentValue) {
console.log(previousValue);
return previousValue + (currentValue.quantity * currentValue.price);
}, 0);
console.log('totalPrice: ', totalPrice);