I am working with ReactJS. I have a JSON Object like this:
[
  {
    "id": "1",
    "category": "cellphones",
    "name": "Xiaomi Redmi Note 10",
    "stock": "99",
    "price": "100",
    "quantity": "3"
  },
  {
    "id": "2",
    "category": "cellphones",
    "name": "Iphone 11",
    "stock": "3",
    "price": "1000",
    "quantity": "5"
  },
  {
    "id": "3",
    "category": "laptops",
    "name": "MSI GF65 Thin",
    "stock": "40",
    "price": "2000",
    "quantity": "2"
  }
]
And i want to get the overall total of this items by doing something like this:
const getAllTotal = () => {
  const sum = cartItems.reduce(
    (prev, next) => prev.quantity * prev.price + next.quantity * next.price,
    0
  );
  console.log(sum);
  return sum;
};
The thing is, everytime i call that function, the console returns NaN.
I first thought it was caused by the type of the keys, so i tried to enclose said keys into the parseInt() method, but it returned the same NaN. What am i doing wrong?
 
     
    