update object value in an array in javascript

 

const storage= [
{
id:1,
name:“kahnu”,
email:[email protected],
age:21,
phone:1234567890
},
{
id:2,
name:“kahnu2”,
email:[email protected],
age:22,
phone:1234567890
},
{
id:3,
name:“kahnu3”,
email:[email protected],
age:23,
phone:1234567890
}
]

const objIndex = storageData.findIndex((obj => obj.id == ‘1’));


storageData[objIndex].name = ‘new name’;
storageData[objIndex].email = ‘new email’;
storageData[objIndex].age = ‘new age’;


console.log(“After update: “, storageData[objIndex])

Leave a Comment

Your email address will not be published. Required fields are marked *