JavaScript: Determine Type of Object
How to find out if a object is function, array, date, regex, etc?
Check If Object is Array
Array.isArray(obj)
-
Return
true
for true array. [see Array-Like Object]
Check If Object is Function
typeof obj === "function"
(also works on Arrow Function)
Other
The most reliable and generic way to determine the type of object is this:
Reflect.apply( Object.prototype.toString , val, [] )
For detail, see Object.prototype.toString
JavaScript Value Types
JavaScript Object and Inheritance
- Object Basics
- Object Overview
- Object Type
- Test If a Value is Object Type π
- Find Object's Type
- Prototype and Inheritance
- Prototype Chain
- Is in Prototype Chain?
- Get/Set Parent
- Show Parent Chain π
- Create Object
- Object Literal Expr
- Create Object + Parent
- Prevent Adding Property
- Clone Object π
- Test Object Equality π
- Add Method to Prototype