Answers for "Javascript How to push a key value pair into a nested object array"

0

Javascript How to 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"
          }
      ]
  }
];

const res=arr.map(nested =>({ id:nested.id, menues:
  nested.menues.map(menu =>({...menu,status:nested.status})) }));
console.log(res);
Posted by: Guest on August-29-2021

Code answers related to "Javascript How to push a key value pair into a nested object array"

Code answers related to "Javascript"

Browse Popular Code Answers by Language