-1

I have an Array like so:

object = [{id: '#obj1'}, {id: '#obj2'}, {id: '#obj3'}, {id: '#obj4'}, 
          {id: '#obj5'}
                ];

and somewhere in my code I want to add elements to this array if a condition is true.

if (condition) {
    // add {id: '#obj6'}, {id: '#obj7'} to the object Array
}

Hope this isn't too difficult.

Thanks.

NotToBrag
  • 655
  • 1
  • 16
  • 36

1 Answers1

0

You can use the push method of the Array

if (condition) {
    object.push({id: '#obj6'}, {id: '#obj7'});
}
Koen Peters
  • 12,798
  • 6
  • 36
  • 59