If I have an object:
var array = [];
var theobject = null;
array.push({song:"The Song", artist:"The Artist"}, {song:"Another Song", artist:"Another Artist"});
and I:
for(var i = 0; i < array.length; i++)
if(array[i].song == "The Song") {
theobject = array[i];
break;
}
If I then changed the object by doing:
theobject.song = "Changed Name";
I am having problems when, even though I am trying to set ONLY "theobject.song" to "Changed Name", the array [0] .song is also set to "Changed Name".
I want "theobject.song" to become "Changed Name", while array [0] .song remains "Song".
What is the best way to do this?
source
share