Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > adding elements to an array...

Thread Tools

adding elements to an array...

Posts: n/a
how to do you add elements to an array? am looking at section dealing
with arrays in JS Bible, can't find how you add to an array.. in the
last few years I've been doing much more Java than JS, am used to Java,
where you can't add elements to an array, but use a Vector instead.. and
it's very easy to add to it (use add() method..) how to you add
elements to an array in JavaScript..

I looked up array obj, don't see method to add to array...

thank you..
Reply With Quote
Martin Honnen
Posts: n/a

Frances wrote:

> how to do you add elements to an array?

There is a push method that adds its arguments to the end of the array e.g.
var a = [0, 1, 2];
Note that push is not supported by IE 5/Win with the JScript 5.0 engine.
You can always do e.g.
a[a.length] = 3;

There are other methods to change the array, see
< #Mutator_methods>


Martin Honnen
Reply With Quote
Michael Winter
Posts: n/a
On 30/05/2006 20:59, Vic Sowers wrote:


> a[-1] = "Zero";
> a["Zero"] = -1;

Neither of these will be array elements.

What constitutes an array index has been described several times (both
by myself and others).

See, for example:

Author: Michael Winter
Date: 2004-12-07 10:26:36
Message-ID: opsimviozvx13kvk@atlantis


in the thread, "Roundup of FAQ change requests".


Michael Winter
Prefix subject with [News] before replying by e-mail.
Reply With Quote

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
XSLT: iterating all child elements and accessing homonymous childrenin sibling elements Gerald Aichholzer XML 2 06-27-2006 03:46 PM
How do I allow both elements or No elements Billy XML 4 09-12-2005 08:29 AM
Elements within elements Jyrki Keisala XML 5 06-15-2005 04:58 PM
container elements for repeating elements ('element farms') needed? Wolfgang Lipp XML 1 01-30-2004 04:09 PM
container elements for repeating elements ('element farms') needed? Wolfgang Lipp XML 0 01-28-2004 02:50 PM