So, I just discovered today that I am doing this:
a = { b: { c: 1, d: 2 }, d: {} }
sub = a.b
// sub is { c: 1, d: 2 }
sub now actually an object stored in a, not a clone.
Now if I do this:
sub.c = "x"
// a is now: { b: { c: 'x', d: 2 }, d: {} } // nice
The same goes for arrays.
So I have this array:
arr = [{a: 1, b: 2}, {c: 3, d: 4}]
sub = arr[1]
I would like to remove subfrom the array so that it arrbecomes: [{a: 1, b: 2}]but if I do sub = null, I just assign a new value sub. The same for delete.
delete sub
So the question is: how to remove {c: 3, d: 4}from an array usingsub
Despite the fact that it works, I cannot use delete arr[1]it because I do not know the index. I save an object using functionmin lodash
source
share