I have a variable that could be an Object, a Map, or neither. I can easily check for objects with typeof
, but I need to conditionally Map.map()
the variable if it is a Map, and typeof
doesn't work with maps. Any suggestions?
Asked
Active
Viewed 1,245 times
2

Vendetta
- 2,078
- 3
- 13
- 31
-
`instanceof` is what you're looking for – Pointy Nov 20 '20 at 21:54
-
@Pointy could I get some context with that? – Vendetta Nov 20 '20 at 21:56
-
1@DeathWaltz — It’s a JS operator. It’s well documented. – Quentin Nov 20 '20 at 21:57
2 Answers
2
var foo = new Set;
foo instanceof Set; // True!
foo instanceof Map; // False!

Or Assayag
- 5,662
- 13
- 57
- 93