0

I have a following code,

var options = {
            'x': 250,
            'isVirtual': true,
          }

 var arr[0] = {
         'y': 250,              
  }

i need to add the options keys(instance) to arr[0].. how to add?

my expectation output is,

arr[0] = {
          'x': 250,
          'isVirtual': true,
          'y': 250,   
}
Akbar Basha
  • 1,168
  • 1
  • 16
  • 38
  • Use `options['y'] = 250;` or `options.y = 250;`. That's not an array it's an object. New properties can be added using `[]` or `.` notation. – Tushar May 26 '16 at 15:13

1 Answers1

4

You can use Object.assign()

var arr = [];
var options = {
  'x': 250,
  'isVirtual': true,
}
arr[0] = {
  'y': 250,
}

Object.assign(arr[0], options);
console.log(arr[0])
Nenad Vracar
  • 118,580
  • 15
  • 151
  • 176