[英]how to push some of the object keys only into another array in react js
我正在從后端獲取一些項目,現在我想創建單獨的重復數組ItemsModels並希望將這些項目發布到后端......可以對此提供任何幫助......
從后端獲取數據
const Items = [
{ uid: "01", item: "Car", carModel: "i 20", model: 2010 },
{ uid: "02", item: "Car", carModel: "i 10", model: 2009 },
{ uid: "03", item: "Car", carModel: "Swift", model: 2011 },
{ uid: "04", item: "Car", carModel: "Polo", model: 2015 }
];
我想要這樣的重復數組....
const ItemsModels = [
{ uid: "01", carModel: "Hundai i 20" },
{ uid: "02", carModel: "Hundai i 10" },
{ uid: "03", carModel: "Swift" },
{ uid: "04", carModel: "Polo" }
];
你可以做一個簡單的地圖
const ItemsModels = Items.map(item => {
const { uid, carModel } = item;
return { uid, carModel };
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.