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

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

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