Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

conditionally add a property to an object

const includeSalary = true;

const employee = { 
	id: 1,
    name: 'Ofir',
    ...(includeSalary && { salary: 1000 }),
}
 
PREVIOUS NEXT
Tagged: #conditionally #add #property #object
ADD COMMENT
Topic
Name
3+5 =