![]() |
Question: Are arrays a separate data type?
Answer:
No, JavaScript arrays are not a separate data type.
In JavaScript, arrays are objects.
However, arrays do have some additional predefined properties and methods, as compared to other objects,
for example, the array.length
property or the array.sort()
method.
You can always check the type of any variable using the typeof
operator.
For a variable that holds an array, the typeof
operator returns object.
Here is an example:
var myArray = new Array (1,7,2,6,3,5,4); alert(myArray.length) // 7 alert(myArray.sort()) // 1,2,3,4,5,6,7 alert(typeof myArray) // object
Copyright © 1999-2011, JavaScripter.net.