-4

Refer this Image

var key = {"kay_1":{
"sample_1":"spmedata", "sample_2":"spmedata", }, "kay_2":{
"sample_1":"spmedata", "sample_2":"spmedata", } }

Now My Question is that how to update and delete "kay_2"->"sample_1" key?

4
  • Use the dot or bracket notation to update value: key['kay_2']['sample_1'] = 'new value'. To delete use delete key['kay_2']['sample_1']. Commented Dec 1, 2015 at 8:38
  • google is your friend Commented Dec 1, 2015 at 8:38
  • Please have a look at: developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/… Commented Dec 1, 2015 at 8:41
  • Need a complete tutorial to manipulate JSON data by Native Javascript. Commented Dec 1, 2015 at 9:11

3 Answers 3

1
var key={"kay_1":{        
             "sample_1":"spmedata",
             "sample_2":"spmedata",
    },
"kay_2":{        
             "sample_1":"spmedata",
             "sample_2":"spmedata",
    }
}

// To update the value
key['kay_2']['sample_1'] = 'new value';

// To delete the key
delete key['kay_2']['sample_1']
Sign up to request clarification or add additional context in comments.

1 Comment

1: Object latlng: Object lat: 37.579412513438385 lng: -99.4976806640625 proto: Object proto: Object 2: Object latlng: Object lat: 37.996162679728116 lng: -90.7745361328125 proto: Object proto: Object proto: Object How to update Object '2' latlng Dynamically? Code will check whether it is object 1 or 2? I have integer value, I have checked it but it becomes object to integer checking?
1

to update both ways could be used

key.kay_2.sample_1 = "changed value";
key['kay_2']['sample_1'] = "changed value";

for delete is the same

delete key.kay_2.sample_1;
delete key['kay_2']['sample_1'];

Comments

0

To modify the value try,

key.kay_2.sample_1 = "changed value";

To delete,

delete key.kay_2.sample_1

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.