Answers for "add properties to object conditionally javascript"

38

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 "add properties to object conditionally javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language