Given this fiddle, does anyone have a suggestion as to how I might update the indices of array1? Or more to the point, any idea how to make the indices of array2 references to indices of array1?
var array1 = [
{num:"one"},
{num:"two"},
{num:"three"}
];
var array2 = [];
var i = array1.length;
while(i--){
if(i!=1)array2.push(array1[i]);
}
array2[0].num = "one updated";
console.log(array2);
console.log(array1);
Obviously, in this codeblock, array1[0] is not updated.
ifromarray1). As it stands,array1[2]is the same object asarray2[0]and is, in fact, updated inarray1as well as inarray2. If you don't want to reverse, iterate in a forward direction.array1[2]is updated, at least when I ran your fiddle.index 2of thearray1is changed from{num:"three"}to{num:"one updated"}.