Is there another way of setting the array values in javascript
Posted
by Dennis
on Stack Overflow
See other posts from Stack Overflow
or by Dennis
Published on 2010-03-20T10:39:10Z
Indexed on
2010/03/20
10:51 UTC
Read the original article
Hit count: 374
arrays
|JavaScript
Hello. Again I'm still new to this javascript thing, so just would like to know if there is another way of setting the values of an array (just like declaring it);
//correct way of declaring an array and reusing
var adata = new Array('1','2','3');
//reusing of variable
adata[0] = '4';
adata[1] = '5';
adata[2] = '6'
This part is my question; I want to declare the values of the array just like declaring them to minimize the number of lines;
//array declaration
var data = new Array('1','2','3');
//reusing of variable
data = ['4','5','6']; ---> (as an example) I get an error msg "Invalid assignment left-hand side"
is this possible? If so, what is the correct syntax? I hope I'm making sense.
Thanking you in advance.
© Stack Overflow or respective owner