I have the array:
[ { x: 0,
y: 1,
z: 2,
w: 3 },
{ x: 1,
y: 2',
z: 3 } ]
How can I pop "w"? I need the result:
[ { x: 0,
y: 1,
z: 2 },
{ x: 1,
y: 2',
z: 3 } ]
I have the array:
[ { x: 0,
y: 1,
z: 2,
w: 3 },
{ x: 1,
y: 2',
z: 3 } ]
How can I pop "w"? I need the result:
[ { x: 0,
y: 1,
z: 2 },
{ x: 1,
y: 2',
z: 3 } ]
w
isn't in an array, it's in an object (which is in an array, as the first entry). You can read its value like this:
var w = theArray[0].w;
you can remove it from the object like this:
delete theArray[0].w;
There's no built-in single operation that reads the value and deletes it, like Array#pop
or Array#splice
do.
Note: It usually doesn't matter, but deleting properties from objects on modern JavaScript engines usually has a negative impact on the performance of reading properties from the object afterward. This is because modern engines create on-the-fly classes for objects (and then subclass them when you add more properties), but deleting a property causes the object to fall back to the much-less-optimized "dictionary" (e.g., map) mode. Of course, this varies by JavaScript engine.