Given
var myHash = new Array();
myHash['key1'] = { Name: 'Object 1' };
myHash['key2'] = { Name: 'Object 2' };
myHash['key3'] = { Name: 'Object 3' };
how do I remove key2
, and object 2
from the hash, that it ends up in a state as if i did:
var myHash = new Array();
myHash['key1'] = { Name: 'Object 1' };
myHash['key3'] = { Name: 'Object 3' };
delete doesnt do what i want;
delete myHash['key2']
simply gives me this:
var myHash = new Array();
myHash['key1'] = { Name: 'Object 1' };
myhash['key2'] = null;
myHash['key3'] = { Name: 'Object 3' };
the only docs i can find on splice
and slice
deal with integer indexers, which i dont have.
Edit: I also do not know that 'key2' is necessarily in position [1]
UPDATE
OK slight red herring, delete does seem to do what i want on the surface, however, im using json2.js to stringify my object to json for pushing back to the server,
after ive deleted, myHash gets serialised as:
[ { Name: 'Object 1' }, null, { Name: 'Object 3' } ]
Is this a bug in json2.js? or is it something im doing wrong with delete?
Thanks