Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

js add props to obj conditionally

const isOnline=true;
const user={
    id:6,
    name:'Frank',
    ...(isOnline &&{active:true}),
}
//{id:6,name:'Frank',active:true}
console.log(user);l
 
PREVIOUS NEXT
Tagged: #js #add #props #obj #conditionally
ADD COMMENT
Topic
Name
4+8 =