我有以下數組recipe = [{ id: "abc123", en: {title: "", description: ""}, es: {titleES: "", descriptionES: ""}},{ id: "abc128", en: {title: "", description: ""}, es: {titleES: "", descriptionES: ""}},{ id: "abc135", en: {title: "", description: ""}, es: {titleES: "", descriptionES: ""}}]我想創建一個包含 1 個對象的新數組,其中包含對象“id”和“en”,如下所示newArray = [{ id: "abc123", title: "", description: ""},{ id: "abc128", title: "", description: ""},{ id: "abc135", title: "", description: ""}]我嘗試了以下操作,但似乎無法正常工作const dataList = []; for (let idx in recipe) { dataList.push({...recipe[idx].id, ...recipeES[idx].all }); }
通過迭代數組來合并一些對象
阿波羅的戰車
2023-07-06 14:57:46