Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old September 26th, 2003, 11:29 AM
Registered User
Join Date: Aug 2003
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default Removing an Element from an Associative Array

I have no problem creating associative arrays and adding indices to them.


var myAssocArray = new Object();
myAssocArray["test1"] = new Object;
myAssocArray["test2"] = new Object;
myAssocArray["test3"] = new Object;
myAssocArray["testn"] = new Object;

I'm just wondering how you remove an index. I'm assuming that
myAssocArray["testn"] = null;

will set it to null, but the index still exists. I really want to remove the index. So that I have testn-1 as the last index for example.

Any ideas?


Old September 26th, 2003, 12:11 PM
Registered User
Join Date: Aug 2003
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts

Nevermind. I answered my own question. You need to use the delete method however this only works in JavaScript 1.2 >. For previous versions, all you can do is set the index to null.

Old September 26th, 2003, 12:15 PM
joefawcett's Avatar
Wrox Author
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts

You can also use the splice method.



Similar Threads
Thread Thread Starter Forum Replies Last Post
first element in array nesting siblings rjonk XSLT 1 May 18th, 2008 03:53 PM
Removing an element izbor XSLT 3 May 8th, 2006 11:00 PM
check if an array element is not undefined crmpicco Javascript How-To 1 October 6th, 2005 11:40 AM
Array Element android66 Javascript 2 November 12th, 2004 04:50 AM
How do I test for an empty array element kmoran Excel VBA 1 October 8th, 2004 03:34 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.