As we all know, we can use if else to add an attribute to object like this:
if(key){
obj[key] = value
}
but I have a lot of keys.
I know I can get this done like this:
keyValues.forEach(({key,value})=>{
if(key){
obj[key] = value
}
}
but i want to know can i do this in another way like:
obj={
[this.key1?'key1':undefined]:this.key1,
[this.key2?'key2':undefined]:this.key2,
}
in this way,the object will get an attribute which key is undefined... how can i do to remove undefined attribute and keep the code style in the second way.