Answers for "how to add object value with condition in javascript"

36

insert condition in a object javascript

const a = {
   ...(someCondition && {b: 5})
}
Posted by: Guest on October-22-2020
1

insert condition in a object javascript

const arr = [
  ...(isConditionTrue() ? [{
    key: 'value'
  }] : [])
];

const obj = {
  ...(isConditionTrue() ? {key: 'value'} : {})
};
Posted by: Guest on January-04-2021

Code answers related to "how to add object value with condition in javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language