Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
| Search | Today's Posts | Mark Forums Read
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To 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 December 4th, 2003, 07:57 PM
Registered User
 
Join Date: Dec 2003
Location: , , .
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default Re-Using an Array (for strings of varying lengths)

Is there a way to re-set an array to null so I can use it multiple times for processing strings of varying lengths on the same page?

I have a 3-page form and am storing the name-value pairs from each page in a cookie.

On the 4th page, I print the name-value pairs from the 3 pages of my form, one page at a time -- I do this by calling a function 3 times & I want to use the same array 3 times.

The 1st page had 8 fields & I printed them out fine using the array.
The 2nd page had 12 fields & I printed them with no problem -- the array size simply expanded.

However, the 3rd page had 11 fields (1 field fewer than the page before it) & when I printed out the 11 3rd page values, it also printed the 12th value left over in the array from my previous page.

How can I "empty out" the array or re-set the array length to zero each time I use it?
 
Old December 5th, 2003, 04:14 PM
Registered User
 
Join Date: Dec 2003
Location: , , .
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I decided to experiment by setting the array's length to zero, before re-using it.

This apparently worked.

If anyone knows of a better solution, please let me know.

Thanks.
 
Old December 6th, 2003, 06:46 AM
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

That's an accepted way, another would be to re-initialise:
Code:
myArray = new Array();
--

Joe




Similar Threads
Thread Thread Starter Forum Replies Last Post
strings as array indexes cwalton Excel VBA 3 July 30th, 2007 02:50 AM
Array of Strings to dll jjd Excel VBA 2 February 26th, 2006 07:25 AM
Array of Strings jjd Visual C++ 1 June 23rd, 2005 02:56 PM
Sorting Array of date strings Arsi C# 4 October 22nd, 2004 04:18 PM
Passing an Array of Strings to a WebService rmau Excel VBA 0 October 27th, 2003 03:59 PM





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