📌  相关文章
📜  如何使用 lodash 更新数组中的整个对象 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:02:57.137000             🧑  作者: Mango

代码示例1
var arr = [{id: 1, name: "Person 1"}, {id:2, name:"Person 2"}];

// Find item index using _.findIndex (thanks @AJ Richardson for comment)
var index = _.findIndex(arr, {id: 1});

// Replace item at index using native splice
arr.splice(index, 1, {id: 100, name: 'New object.'});

// "console.log" result
document.write(JSON.stringify( arr ));