const arr = [
{ id: 1, language: 'javascript' },
{ id: 2, language: 'node.js' },
{ id: 3, language: 'typescript' },
{ id: 4, language: 'php' },
];
const index = arr.findIndex(object => {
return object.id === 4;
});
if (index !== -1) {
arr[index].language = 'c++';
}
console.log(arr);
/*
run:
[{
id: 1,
language: "javascript"
}, {
id: 2,
language: "node.js"
}, {
id: 3,
language: "typescript"
}, {
id: 4,
language: "c++"
}]
*/