Answers for "how to add one key value in array of objects using es6"

1

Javascript push a key value pair into a nested object array

arr = [
  {
      "id": 1,
      "status": "pending",
      "menues": [
          {
              "title": "Coke",
              "price": "200"
          }
      ]
  },
  {
      "id": 2,
      "status": "delivered",
      "menues": [
          {
              "title": "Pepsi",
              "price": "120"
          }
      ]
  }
];

arr.forEach(nested => {
    nested.menues.forEach(menu => menu.status = nested.status);
    delete nested.status
});
console.log(arr);
Posted by: Guest on August-28-2021
0

add new key in array objects using map

const newArr = [
  {name: 'eve'},
  {name: 'john'},
  {name: 'jane'}
].map(v => ({...v, isActive: true}))
Posted by: Guest on August-10-2021

Code answers related to "how to add one key value in array of objects using es6"

Code answers related to "Javascript"

Browse Popular Code Answers by Language