javascript arrays: adding entries
Posted
by Lyon
on Stack Overflow
See other posts from Stack Overflow
or by Lyon
Published on 2010-04-17T09:21:02Z
Indexed on
2010/04/17
9:23 UTC
Read the original article
Hit count: 337
Hi,
I'm not sure how I would do this in Javascript. I want to create an array that would contain any number of error messages from my form.
I read on websites that you define the key for that array when adding new entries.
// Javascript
var messages = new Array();
messages[0] = 'Message 1';
How can I add entries into my array using a similar method I normally do in PHP
// PHP
$messages = array();
$messages[] = 'Message 1'; // automatically assigned key 0
$messages[] = 'Message 2'; // automatically assigned key 1
Is it possible to emulate that in Javascript? I don't want to have to define the number of entries in my array as it can vary.
Thanks for helping me out on this very basic js question. -Lyon
© Stack Overflow or respective owner