流浪のwolf

卷帝

导航

查看属性是否在对象里

使用 in 查看;

   let condition = true
      const obj = {
        name: '朱龙旭',
        ...(condition && { age: 24 }),
      }
      console.log('name' in obj) // true
      console.log('age' in obj) // true

 

posted on 2022-08-22 16:14  流浪のwolf  阅读(7)  评论(0编辑  收藏  举报