Referenced from :
let myArray = [
{id: 0, name: "Jhon"},
{id: 1, name: "Sara"},
{id: 2, name: "Domnic"},
{id: 3, name: "Bravo"}
],
//Identify the index of a specific object using findIndex method.
objIndex = myArray.findIndex((obj => obj.id == 1));
//Display object in Console.
console.log("Before update: ", myArray[objIndex])
//Modify object's name property.
myArray[objIndex].name = "Laila"
//Display updated object in console.
console.log("After update: ", myArray[objIndex])
//Identify index of specific object utilizing findIndex method.
objIndex = myArray.findIndex((obj => obj.id == 1));
In the snippet above, I'm using obj.id == 1
.
I intend to make it dynamic and not rigid. Is there a way to accomplish this?