views:

2115

answers:

2

if I have a JSON object say:

var myObj = {'test' : {'key1' : 'value', 'key2': 'value'}}

can I remove 'key1' so it becomes:

{'test' : {'key2': 'value'}}
+13  A: 

Simple:

delete myObj.test.key1;
Josef
delete myObj.test['key1']; would work as well.
CptSkippy
So would `delete myObj['test']['key1']`; you can interchange `whatever.x` and `whatever['x']` as long as `x` is a valid variable name, so even `delete myObj['test'].key1` would work.
Sinan Taifour
A: 

Hi, for me, nothing i try works :-(

I have this json: jsonStrData.users='[{"id":7,"text":"Peter"},{"id":5,"text":"Sylvia"},{"id":6,"text":"Valeria"}]';

and need to remove one object, based on its id value (for instance: 5), so the new json will be: jsonStrData.users='[{"id":7,"text":"Peter"},{"id":6,"text":"Valeria"}]';

Please, help me - wow must I do ?

Vagner
you need to remove the second object in the array. this is different from the question asked and answered.
Schotime
-1: create a new question
opyate