Forum Moderators: open

Message Too Old, No Replies

Delete element from associative array

         

a440guy

8:38 pm on Sep 22, 2004 (gmt 0)

10+ Year Member



How does one delete an element from an associative array? For example, I have:

var a = new Object();
a['title'] = 'Mr.';
a["fname'] = 'Brad';
a['lname'] = 'Johnson';

I want to remove the 'title' entry (so that it doesn't exist, not merely give it a null value).

Blackbird42

9:50 pm on Sep 22, 2004 (gmt 0)

10+ Year Member



Just type

delete a['title'];

since title is just a property of a.

Rambo Tribble

10:44 pm on Sep 22, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You might wish to note that if the delete action is successful it returns true and that the property then becomes undefined.

a440guy

12:01 pm on Sep 23, 2004 (gmt 0)

10+ Year Member



Ah! So simple. Thanks!