I have a number of objects collected in an array. The same objects are also tied to some DOM elements for various reasons. From time to time I need to update one of these objects. The easiest way to do this is to find an object in the array with the same id property as the one that received the new values ββthrough AJAX, and then replace it. But this, of course, creates a new object, and the objects attached to the DOM elements no longer match. This means that if I compared them, they would not be the same object anymore.
How can I easily replace the correct object with the values ββin the new object without replacing the actual object? (So ββthe link remains the same)
An example of what I do not want
var values = [{id:1, name:'Bob'}, {id:2, name:'Alice'}, {id:3, name:'Charlie'}]; var bar = values[2]; console.info(bar === values[0]);
The only way I can think of is to iterate over the object using foreach or something like that, but hoping there is something built into javascript or jQuery or something that allows you to use a more efficient or at least least cleaner code.
source share