what is the best way to update an object's property in an array of objects
Unanswered
Pacific cod posted this in #help-forum
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
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
@Pacific cod 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;
}
how many objects in the array. How many of those do you need to update. How many stay the same. do you need an index. How are you descerning what object needs what.
you have left a lot unanswered
Pacific codOP
okay I'll update the question.
@DirtyCajunRice | AppDir you have left a lot unanswered
Pacific codOP
I think I fixxed it