Answers for "js conditionally add property to object"

36

js conditional object property

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

conditionally add property to object ts

const a = {
   ...(someCondition && {b: 5})
}
Posted by: Guest on December-09-2020
0

conditional object spread

var cond = true;

var extraInfo = [
  {
    a: 11,
    b: 25
  },
  {
    a: 12,
    b: 34
  },
  {
    a: 1,
    c: 99
  }
];

var userInfo = [
  {
    z: 8
  },
  {
    z: 10
  },
  ...(cond ? extraInfo : [])
];

console.log( userInfo );
Posted by: Guest on November-02-2020

Code answers related to "js conditionally add property to object"

Code answers related to "Javascript"

Browse Popular Code Answers by Language