Here, i am trying to add 'order_total' property. I have used reduce method, if try for only arrays, the same code is working properly, but when i implemented on array of objects it is resulting NaN.
var user = {
id: 16,
username: 'smith',
email: 'smith@gmail.com',
order: [
{
id: 71,
order_number: 'DCT-123',
order_total: 12000,
},
{
id: 71,
order_number: 'DCT-345',
order_total: 7000,
},
{
id: 71,
order_number: 'DCT-321',
order_total: 2000,
}
]
};
var result = user.order.reduce(function(a, b) {
return a.order_total + b.order_total;
});
console.log(result);