You can use instanceof
let a = new Set()
let b = [1,2]
console.log(a instanceof Set)
console.log(b instanceof Set)
On side note :-
You can also use [] instanceof Array
. However, Array.isArray
was created for a specific purpose: avoiding an issue with instanceof. Namely, window1.Array != window2.array;
thus, new window1.Array() instanceof window2.Array == false
. Same logic holds for Set. As long as you don't mess with multiple global environments, instanceof is fine. If you do, b.toString() == "[object Set]"
might be better. Thanks to @andman for pointing out.