0

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?

1 Answer 1

3
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"]}})
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks thats the function i was looking for :) is there a similiar function to "add" or would i have to look the data to add to it (which is currently how i do it but if theres a adding function that would strip some code chunks down :)
No; "adding" is already implemented via assigning, so there's no quick way (unless you find the JavaScript equivalent of collections.defaultdict).
Ah so my loop to "push" to it is the only way to do it ?

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.