Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

conditionally add property to object

const trueCondition = true;const falseCondition = false;const obj = {  ...(trueCondition && { dogs: "woof" }),  ...(falseCondition && { cats: "meow" }),};// { dogs: 'woof' }
Source by amberley.dev #
 
PREVIOUS NEXT
Tagged: #conditionally #add #property #object
ADD COMMENT
Topic
Name
4+1 =