Next.js Discord

Discord Forum

what is the best way to update an object's property in an array of objects

Unanswered
Pacific cod posted this in #help-forum
Open in Discord
Pacific codOP
Hi
I want to update an array of objects and found this article that suggest 6 different ways. I was wondering which one would be the most suitable for my case. The array I'm trying to update is stored in the local storage.

I need to add this array is a cart array. One you would have in online shops, and when any user wants to increase the quntity of some perviously added product they click a button, then only one property of the product object which is the quntity will be increased by one.

This is the article
https://bobbyhadz.com/blog/javascript-update-property-of-object-in-array#update-an-objects-property-in-an-array-of-objects-using-for

The Object
{
  id: string;
  productName: string;
  productAddressName: string;
  price: number;
  quntity: number;
  image: string;
}

4 Replies