Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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 );
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript insert before 
Javascript :: fetch post 
Javascript :: refresh after delete in node 
Javascript :: javascript subtract 2 dates get difference in minutes 
Javascript :: nodejs current timestamp unix 
Javascript :: how to create jquery function 
Javascript :: formik stepper form 
Javascript :: replace data in files in node.js 
Javascript :: lodash remove undefined values from object 
Javascript :: json to csv nodejs 
Javascript :: make contenteditable false javascript 
Javascript :: sequelize delete item 
Javascript :: get css custom property javascript 
Javascript :: navigator.clipboard is undefined 
Javascript :: regex for email 
Javascript :: jquery on ready 
Javascript :: node js throw error 
Javascript :: js indexof regex 
Javascript :: difference between call and apply in js 
Javascript :: javascript append to array 
Javascript :: mongoose find one and update with new field 
Javascript :: javascript check less width of window 
Javascript :: uploadgetfiletypefileextension 
Javascript :: javascript backslash 
Javascript :: loop in react depending on number 
Javascript :: ckeditor get value 
Javascript :: html javascript type 
Javascript :: $.post jquery beforesend loader 
Javascript :: jquery get selected dropdown item 
Javascript :: get first element by class name jquery 
ADD CONTENT
Topic
Content
Source link
Name
8+9 =