1

I found the way to delete an item of associative array by :

delete array['knownkey'];

but what about delete the whole associative array,I mean just like empty an normal array:

the way to empty an normal array is [I found on the google]:

array = []  //or
array.length = 0 

So,the associative array has the way to empty or remove the all items at once ....

2 Answers 2

3
assoc_array = {};

Should set assoc_array to an empty object (aka associative array in JavaScript).

Thanks to garbage collection, there is no real need to empty an existing object. You just go get a new one.

Sign up to request clarification or add additional context in comments.

1 Comment

+1 for mentioning that this will NOT empty an existing object, but create a new (empty) one. Any references to the old one should still see the old data.
0

What's wrong with:

array = {}

..?

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.