javascript arrays: adding entries
- by Lyon
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