Arrays in JavaScript

Posted by caramel1991 on Stack Overflow See other posts from Stack Overflow or by caramel1991
Published on 2010-03-16T16:53:26Z Indexed on 2010/03/16 17:01 UTC
Read the original article Hit count: 284

Filed under:

While reading a book about JavaScript I stumbled across an example:

var names = new Array("Paul","Catherine","Steve");
var ages = new Array(31,29,34);
var concatArray;
concatArray = names.concat(ages);

My question is, why doesn't the variable concatArray need to be define as a new Array() in order to store the concatenated data for both arrays name and ages , but when I try to treat the concatArray as an array by adding another line of code "document.write(concatArray[0])", it works just like an array and shows me the data stored in the first element. I just wonder why I'm not declaring the concatArray as a new array, yet it still works as one.

© Stack Overflow or respective owner

Related posts about JavaScript