【问题标题】:Programmatically Determining when a Variable is a Set [duplicate]以编程方式确定变量何时为集合
【发布时间】:2019-11-27 22:48:20
【问题描述】:

NodeJS中是否可以判断一个变量是否为Set of not?

也就是这段代码

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

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

报告两个变量都包含object

object
object

是否有一种内置方法来确定一个变量是否包含一个集合?如果不是,是否有用于确定变量是否为集合的通用启发式方法?

【问题讨论】:

    标签: javascript node.js ecmascript-6


    【解决方案1】:

    你试过instanceof吗?

    let thing1 = new Set([1,2,3])
    let thing2 = [1,2,3]
    
    console.log(thing1 instanceof Set)
    console.log(thing2 instanceof Set)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-11-07
      • 2014-04-18
      • 1970-01-01
      • 2023-02-14
      • 1970-01-01
      • 2014-01-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多