javascript - Find and update an object in an array -


i want object array of objects, update it.

var myobjs = [{ id: 1, name: "foo"}, { id: 2, name: "bar" }];  var myobjecttoupdate = _.findwhere(myobjs, { id: 2 });  myobjecttoupdate = { id: 2, name: "boop" };  myobjs[1] // { id: 2, name: "boop" } 

currently when update myobject in 3rd line, not update array of objects. i'm assuming updating new variable instead of referencing.

what correct way this?

@e_net4 correct, reassigning object found.

if need update name, try this:

var myobjs = [{ id: 1, name: "foo"}, { id: 2, name: "bar" }];  var myobjecttoupdate = _.findwhere(myobjs, { id: 2 });  myobjecttoupdate.name = "boop";  myobjs[1] // { id: 2, name: "boop" } 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -