📌  相关文章
📜  Javascript 如何将键值对推送到嵌套对象数组中 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:04:27.249000             🧑  作者: Mango

代码示例1
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);