let variable = false
let object = {}
object = {
...object,
...(variable && {add: true})
}
console.log(object) // {}
variable = true
object = {
...object,
...(variable && {add: true})
}
console.log(object) // {add: true}
标签:...,log,object,add,添加,variable,true,属性 From: https://www.cnblogs.com/wq2022/p/16810356.html