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 ....

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
qinHaiXiang
  • 6,051
  • 12
  • 47
  • 61

2 Answers2

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.

Ates Goral
  • 137,716
  • 26
  • 137
  • 190
  • 4
    +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. – Thilo Jan 17 '11 at 06:57
0

What's wrong with:

array = {}

..?

Gabi Purcaru
  • 30,940
  • 9
  • 79
  • 95