Is it possible to swap a reference of an object that an array element contains to another index and remove/delete the old index.
Example: I have an array of OBJECTS with indexes A, B, C, D.
Now I want to create a new array element with index F and assign it the reference of an object that index B contains. After that, I want to remove B from the array so that only A, C, D, E remains.
What I basically want to do is copy the reference of an object that index B contains and copy it to E.
I have tried the code below but it doesn't work:
this.cache['A'] = new Orange(1);
this.cache['B'] = new Orange(2);
this.cache['C'] = new Orange(3);
this.cache['D'] = new Orange(4);
// I want to pass the reference B contains
// and assign it to F (like something you can do in C++)
this.cache['E'] = this.cache['B'];
// First attempt
// length of array is 5 (cache['B'] just has value of undefined)
delete this.cache['B'];
// Second attempt
// the reference to object Orange was deleted in both B and E
this.cache.splice('B', 1);
I don't want to create a new object and reassign the values, because there are many references and bindings to the objects, so doing a deep copy would be meaningless.