const data = [
{
id: 1,
title: "buttermilk pancakes",
category: "fullstack",
price: 15.99,
img: "./img/item-1.jpeg",
desc: `I'm baby woke mlkshk wolf bitters live-edge blue bottle, hammock freegan copper mug whatever cold-pressed `,
},
{
id: 2,
title: "diner double",
category: "backend",
price: 13.99,
img: "./img/item-2.jpeg",
desc: `vaporware iPhone mumblecore selvage raw denim slow-carb leggings gochujang helvetica man braid jianbing. Marfa thundercats `,
},
];
export default data;
Here i looped through the object using map but the returned result displays the iterated price sums. I also used the JavaScript function reduce and that did not work either.
const Test = () => {
let sum = 0;
return (
<div>
{data.map((items) => {
const values = items.price;
sum = values + sum;
console.log(Math.max(sum));
const { id } = items;
return (
<div key={id}>
<p>{sum}</p>
</div>
);
})}
</div>
);
};
How do I get the total value of the price using react?