javascript - How Do I loop this arrays to extract only the orderTotal? -
how loop array , add ordertotal field inside item object? (0) ordertotal $100 (1) ordertotal $220
var sum = 320;
save sum of both ordertotal field variable
my goal sum of order total fields
[ { "itemid": "c619d69c-970d-11e7-afd4-e44bb50029cc", "itemtype": "job", "item": { "jobcolor": "18, 2, 218", "jobtype": "work", "employeeids": [ "af879a7d-1aec-e111-834a-002590274606" ], "note": "", "jobstatus": "scheduled", "actualdatetimestart": "9/13/2017 11:00 am", "ordertotal**": 100, "orderrefnumber": "", "ordernumber": 8375, "ordertype": "estimate", "siteid": "56f6f468-957c-11e7-b464-b4bf180545bb" } }, { "itemid": "f9cf5384-9244-11e7-9bca-e81c6a1ca1cb", "itemtype": "job", "item": { "jobcolor": "255, 126, 0", "jobtype": "work", "employeeids": [ "af879a7d-1aec-e111-834a-002590274606" ], "note": "", "jobstatus": "scheduled", "actualdatetimestart": "9/13/2017 2:00 pm", "ordergroup": "", "ordertotal": 220, "orderrefnumber": "", "ordernumber": 8367, "ordertype": "work order", "siteid": "7e131f90-6657-11e7-8416-875831a581c3" }
you can reduce array this:
const sum = orders.reduce((acc, order) => acc + order.ordertotal, 0);
Comments
Post a Comment