The JavaScript typeof statement is useful in for data validation. JavaScript typeof Array return "object"
because array
is technically a type of object
.
typeof [] === "Object"
typeof 123 === "number"
In JS everything but primitives are objects. Primitives are : Numbers , Booleans , Null , Undefined , String , Symbol
The rest are objects (arrays, objects, maps, sets…)
Check if the variable is an array in couple of ways:
var isArr = data instanceof Array;
var isArr = Array.isArray(data);
JavaScript typeof array
Simple example code typeof array is an object.
<!DOCTYPE html>
<html>
<body>
<script>
const arr = [2,4,6,8]
const obj = { type: 'Gear', valid: true }
console.log(typeof arr)
console.log(typeof obj)
</script>
</body>
</html>
Output:

Read: Check if object is Array JavaScript
Do comment if you have any doubts or suggestions on this Js Array topic.
Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.
OS: Windows 10
Code: HTML 5 Version

Degree in Computer Science and Engineer: App Developer and has multiple Programming languages experience. Enthusiasm for technology & like learning technical.