https://bobbyhadz.com/blog/javascript-update-property-of-object-in-array
Sunday, January 30, 2022
Change value of object which is inside an array
//Initailize array of objects.
let myArray = [
{id: 0, name: "Jhon"},
{id: 1, name: "Sara"},
{id: 2, name: "Domnic"},
{id: 3, name: "Bravo"}
],
//Find index of specific object using findIndex method.
objIndex = myArray.findIndex((obj => obj.id == 1));
//Log object to Console.
console.log("Before update: ", myArray[objIndex])
//Update object's name property.
myArray[objIndex].name = "Laila"
//Log object to console again.
console.log("After update: ", myArray[objIndex])
Subscribe to:
Posts (Atom)
-
https://www.nicesnippets.com/blog/laravel-9-comment-system-example-tutorial
-
Organization : Keeping each site's configuration in separate files makes the server easier to manage, especially when hosting multiple...
-
On one end of the spectrum, you have your no-code dogmatics. On the other end, you have your fancy tech stack enthusiasts. In the middle a...