查看属性是否在对象里
使用 in 查看;
let condition = true
const obj = {
name: '朱龙旭',
...(condition && { age: 24 }),
}
console.log('name' in obj) // true
console.log('age' in obj) // true
卷帝
使用 in 查看;
let condition = true
const obj = {
name: '朱龙旭',
...(condition && { age: 24 }),
}
console.log('name' in obj) // true
console.log('age' in obj) // true