Вот простая, аннотированная альтернатива с Array.findIndex()
:
staff = [{
name: "Mark",
dept: "Sales",
address: "123 Fake St"
},
{
name: "Jim",
dept: "Sales",
address: "123 Real St"
},
{
name: "Fred",
dept: "Sales",
address: "123 Imaginary Ln"
}
];
console.dir(staff);
// Find the index of the person based on whatever criteria you want
index = staff.findIndex(person => person.name === "Jim");
// Update that index with a new object
staff[index] = {
// Retain values you don't want to change
name: staff[index].name,
address: staff[index].address,
// Change those you do
dept: "Development"
}
console.dir(staff);