Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old September 26th, 2003, 11:29 AM
Registered User
 
Join Date: Aug 2003
Location: , , .
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.

e.g.

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?

Nick

Reply With Quote
  #2 (permalink)  
Old September 26th, 2003, 12:11 PM
Registered User
 
Join Date: Aug 2003
Location: , , .
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.


Reply With Quote
  #3 (permalink)  
Old September 26th, 2003, 12:15 PM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

You can also use the splice method.
http://msdn.microsoft.com/library/de...smthsplice.asp

--

Joe
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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 03:50 AM
How do I test for an empty array element kmoran Excel VBA 1 October 8th, 2004 03:34 AM



All times are GMT -4. The time now is 07:03 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.