-2

Is it possible to determine whether a variable is a Set of not in NodeJS?

That is, this code

let thing1 = new Set([1,2,3])
let thing2 = [1,2,3]

console.log(typeof thing1)
console.log(typeof thing2)

reports that both variables contain an object

object
object

Is there a built-in way to determine if one variable contains a set or not? If not, is there a common heuristic used to determine if a variable is a set or not?

Herohtar
  • 5,347
  • 4
  • 31
  • 41
Alana Storm
  • 164,128
  • 91
  • 395
  • 599

1 Answers1

0

Have you tried instanceof?

let thing1 = new Set([1,2,3])
let thing2 = [1,2,3]

console.log(thing1 instanceof Set)
console.log(thing2 instanceof Set)
Nathan Surfus
  • 129
  • 1
  • 5