Answers for "js append key value pair to array"

0

add key value pair to all objects in array

var arrOfObj = [{
  name: 'eve'
}, {
  name: 'john'
}, {
  name: 'jane'
}];

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

console.log(arrOfObj);
console.log(result);
Posted by: Guest on October-07-2020
1

javascript push dictionary into array

var dict = []; // create an empty array

dict.push({
    key:   "keyName",
    value: "the value"
});
Posted by: Guest on February-25-2021

Code answers related to "js append key value pair to array"

Code answers related to "TypeScript"

Browse Popular Code Answers by Language