ES6 Array and Object

Array

Append key and value all object

var result = arrOfObj.map(function(el) {
  var o = Object.assign({}, el);
  o.isActive = true;
  return o;
});

Get Partial key and value when Object Array

const devices = [{scenarioId: 'a', key: 'value}, {scenarioId: 'b', key: 'value'}]

// exepected output
// ids = ['a', 'b']
const ids = devices.map((device) => device.scenarioId);
// eleminate id===null
const ids = devices.map(device => device.scenarioId).filter(id => id !== null);