Try this:
<script language="JavaScript">
var dest=0;
NewArray = new Array();
for( src in ArrayName )
{
NewArray[dest++] = ArrayName[src];
}
ArrayName = NewArray;
</script>
This will pack all entries into the array, starting with the first
slot in it. If you really want to skip the first slot and begin with
the second (as indicated in your post), replacing "dest++" with "++dest"
should do the trick.
--
Michael F. Stemper
#include <Standard_Disclaimer>
The FAQ for rec.arts.sf.written is at:
http://www.geocities.com/evelynleeper/sf-written.htm
Please read it before posting.
> In article <3e9a6a78$1...@usenet.per.paradox.net.au>, "Adam"
> <adams...@hotmail.com> writes:
>>Say I have an array like below:
>>
>>ArrayName[1] = "Text Here 1"
>>ArrayName[4] = "Text Here 4"
>>ArrayName[8] = "Text Here 8"
>>ArrayName[9] = "Text Here 9"
>>
>>Is there a simple way to get these arrays so they are like:
>>
>>ArrayName[1] = "Text Here 1"
>>ArrayName[2] = "Text Here 4"
>>ArrayName[3] = "Text Here 8"
>>ArrayName[4] = "Text Here 9"
>
> Try this:
>
> <script language="JavaScript">
> var dest=0;
> NewArray = new Array();
> for( src in ArrayName )
> {
> NewArray[dest++] = ArrayName[src];
> }
> ArrayName = NewArray;
> </script>
>
Without a loop is quicker.
Array must not have '~'s
<script language="JavaScript">
ArrayName=new Array
ArrayName[1] = "Text Here 1"
ArrayName[4] = "Text Here 4"
ArrayName[8] = "Text Here 8"
ArrayName[9] = "Text Here 9"
ArrayName =
ArrayName.join('~').replace(/~+/g,'~').replace(/^~/,'').split('~')
alert(ArrayName)
</SCRIPT>
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
> Without a loop is quicker. Array must not have '~'s
> ArrayName = ArrayName.join('~').replace(/~+/g,'~').replace(/^~/,'')
> .split('~')
Wouldn't it be kinda slower? String operations are usually fairly
"intensive", and only that, but you run two whole regex runs, requiring the
regex parser to startup. Anyway, it's shorter, but is that better? I'm not
sure, as I dont know the internals of JavaScript, but I'd go with the loop
personally... :)
Svend
stud.useless.scient