Reputation: 79686
According to Professional Javascript for Web developers array is not a datatype in Javascript:
❑ “undefined” if the value is undefined
❑ “boolean” if the value is a Boolean
❑ “string” if the value is a string
❑ “number” if the value is a number
❑ “object” if the value is an object or null
❑ “function” if the value is a function
Is that correct?
Upvotes: 4
Views: 4728
Reputation: 11
yes , Array is not a data type in JavaScript. The set of types in JavaScript are of Primitive values and Objects.
So Array falls under the category of Objects.
Upvotes: 1
Reputation: 1
Arrays are not a data type in Javascript because under the hood they are objects with key:value pairs. Where the keys are the index and values are the array content. For example
let example = ["a","b","c","d","e"]
is the same as an object representation
let example = {
0: "a",
1: "b",
2: "c",
3: "d",
4: "e"
};
Upvotes: -1
Reputation: 10119
As others say it's treated as "object". You can test for an object being an array by checking if its constructor is === to Array.
Upvotes: 1
Reputation: 630389
This is correct, Array is just a descendant of object
. Note though it does override a few things, for example .toString()
in an array prints it's members in a comma list, instead of "[Object object]"
like a plain object would.
Upvotes: 5