Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

js object make attribute conditionally

// JS object add attribute conditionally
const isActive = true;

const obj = { 
	id: 1,
    ...(isActive && { active: true }),
}
Source by amberley.dev #
 
PREVIOUS NEXT
Tagged: #js #object #attribute #conditionally
ADD COMMENT
Topic
Name
1+6 =