Answers for "how to update whole object in array using lodash"

-2

how to update whole object in array using lodash

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 ));
Posted by: Guest on September-23-2020

Code answers related to "how to update whole object in array using lodash"

Code answers related to "Javascript"

Browse Popular Code Answers by Language