I'm trying to check the type of a variable. like below
var a = {a : '1'}
console.log(Object.getPrototypeOf(a));
var b = [1,2,3]
console.log(Object.getPrototypeOf(b));
output in MDN playground
> Object { }
> Array []
Now, I need to get boolean value based on the type.
for,
Object -> true
Array -> false
by using some kind of if conditions or any.
How to get boolean value if the type of variable is object or array ?
I'm mainly looking for somecondition which checks for object type like [3, 3] instanceof Array ==> true checks for array
Use ... instanceof Array
[3, 3] instanceof Array //> true
({"a": "b"}) instanceof Array //> false