Ganti Elemen Array JavaScript
// Replace 1 array element at index with item
arr.splice(index,1,item);
Kaotik
// Replace 1 array element at index with item
arr.splice(index,1,item);
array.splice(array.indexOf(valueToReplace), 1, newValue);
var users = [
{id: 1, firstname: 'John', lastname: 'Ken'},
{id: 2, firstname: 'Robin', lastname: 'Hood'},
{id: 3, firstname: 'William', lastname: 'Cook'}
];
var editedUser = {id: 2, firstname: 'Michael', lastname: 'Angelo'};
users = users.map(u => u.id !== editedUser.id ? u : editedUser);
console.log('users -> ', users);
Run code snippet