Answers for "js add to array conditionally"

0

js add to array conditionally

const cond = false;
const arr = [
  ...(cond ? ['a'] : []),
  'b',
];
// result: 
//if cond true: ['a','b']
//if cond false: ['b']

// from https://2ality.com/2017/04/conditional-literal-entries.html
Posted by: Guest on April-19-2022

Code answers related to "js add to array conditionally"

Code answers related to "Javascript"

Browse Popular Code Answers by Language