insert condition in a object javascript

53

insert condition in a object javascript -

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

const obj = {
  ...(isConditionTrue() ? {key: 'value'} : {})
};

insert condition in a object javascript -

const a = {
   ...(someCondition && {b: 5})
}

Comments

Submit
0 Comments