javascript - Remove item in array without deleting the object it points to -


i have this

var myarray = []; myarray.push(someobject); 

but if delete or splice array entry pushed deletes someobject(someobject passed reference pushing, not clone , cannot have clone). there way can:

  1. just remove pointer someobject myarray without deleting someobject
  2. have delete actual key object in array, not shift other keys in array?

someobject not deleted long other variable or object in javascript has reference someobject. if nobody else has reference it, garbage collected (cleaned javascript interpreter) because when nobody has reference it, cannot used code anyway.

here relevant example:

var x = {}; x.foo = 3;  var y = []; y.push(x); y.length = 0;   // removes items y  console.log(x); // x still exists because there's reference in x variable  x = 0;          // replace 1 reference x                 // former object x deleted because                  // nobody has reference more 

or done different way:

var x = {}; x.foo = 3;  var y = []; y.push(x);      // store reference x in y array x = 0;          // replaces reference in x simple number  console.log(y[0]); // object in x still exists because                     // there's reference in y array  y.length = 0;      // clear out y array                    // former object x deleted because                     // nobody has reference more 

Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -