0

If I create an array, and an object. Then assign the object to an index of the array. I can edit the properties of the object without touching the array and If I try to accesses it through the array the updated properties are reflected.

I then want to delete the object and have the array clear those indices. I hoped I could do this by setting it to null. Dosen't seem to be the case. Heres simplified nodejs console output below

> var ar = [[],[]]
undefined
> var cool = {story: "bro"};
undefined
> ar[0][20] = cool
{ story: 'bro' }
> cool.story = "gurl"
'gurl'
> ar[0][20]
{ story: 'gurl' }
> cool = null
null
> ar[0][20]
{ story: 'gurl' }
kevzettler
  • 4,783
  • 15
  • 58
  • 103
  • 4
    You cannot. JS is a garbage-collected language; you will need to nullifiy all references to an object to get rid of it. Do `arr[0][20] = null` – Bergi Oct 26 '14 at 21:36
  • 2
    With objects and arrays you do indeed assign a reference pointer in JS – Jonathan Gray Oct 26 '14 at 21:43
  • 1
    I just learned something. This cleared it up for me: http://stackoverflow.com/questions/8318357/javascript-pointer-reference-craziness-can-someone-explain-this –  Oct 26 '14 at 21:48

0 Answers0