I have a very simple problem. I wanted to get the total gross using reduce function.
My problem is that its a string but I already added +
to make it a number. I wonder that output is still NaN
?
const hello = [
{
"gross": "391.50",
},
{
"gross": "489.80",
}
]
const final = hello.reduce((prev, cur) => Number(prev.gross) + Number(cur.gross), 0);
console.log(final, 'FINAL')