Answers for "conditionally add object property js"

36

js conditional object property

const a = {
   ...(someCondition && {b: 5})
}
Posted by: Guest on October-22-2020
0

conditionally add property to object

const trueCondition = true;const falseCondition = false;const obj = {  ...(trueCondition && { dogs: "woof" }),  ...(falseCondition && { cats: "meow" }),};// { dogs: 'woof' }
Posted by: Guest on September-13-2021

Code answers related to "conditionally add object property js"

Code answers related to "Javascript"

Browse Popular Code Answers by Language