update object value in an array in javascript

 

const storage= [
{
id:1,
name:“kahnu”,
email:“kahnu@gmail.com”,
age:21,
phone:1234567890
},
{
id:2,
name:“kahnu2”,
email:“kahnu2@gmail.com”,
age:22,
phone:1234567890
},
{
id:3,
name:“kahnu3”,
email:“kahnu3@gmail.com”,
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 *