Sir
Sir

Reputation: 8280

Removing data from a variable

I have a variable which carries information but i want to be able to remove the information some how.

I tried to set the .length = 0 but that didn't seem to work...

The current data of the variable (example data is):

var data = {"1":{"7":["310"],"22":["309"]}}

In english that is:

var data = {"X":{"Y":["ID"],"Y":["ID"]}}

So if i wanted to remove:

X: 1 Y : 22 

The result of data would be:

var data = {"1":{"7":["310"]}};

This is what i tried:

data[X][Y].length = 0;

But that doesn't seem to work, any one understand how to do it?

Upvotes: 0

Views: 51

Answers (1)

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 798686

js> var data = {"1":{"7":["310"],"22":["309"]}}
js> data
({1:{7:["310"], 22:["309"]}})
js> delete data[1][22]
true
js> data
({1:{7:["310"]}})

Upvotes: 3

Related Questions