I have one list as follows
var data = [{id:1, name:'user1', img:'img1.jpg' },{id:2, 'user2', img:'img2.jpg' }]
Now I have to replace img property with new value (e.g. 'New_Image_2.jpg') for id=2 using underscore.js or in javascript using less effort. right now I have created one small function as follows.
var imgpath = 'New_Image_2.jpg';
var tmpdata = _.findWhere(data,{id:2});
if (tmpdata) {
tmpdata.img = imgpath;
}
Now, in above method, my problem is, How to marge new value with original data?
_.findWhere(data,{id:2});returns the actual object and you are mutating the object. So, the changes are actually made in the object which hasimg2.jpgdatain your question is invalid (missingname:in front of 'user2')