1 回答
TA贡献1850条经验 获得超11个赞
您可以简单地使用Array.map.
var source = [
{
"personId": 1,
"personName": "Steve",
"CarName": "Swift",
"Price": "30L",
"OwnerType": "FirstHand",
"Address" : "xxx yyyy zzzz",
"Model" : "2015"
},
{
"personId": 2,
"personName": "Mike",
"CarName": "Breeza",
"Price": "40L",
"OwnerType": "SecondHand",
"Address" : "yyy uuu tttt",
"Model" : "2013"
},
{
"personId": 3,
"personName": "Elle",
"CarName": "Innova",
"Price": "70L",
"OwnerType": "FirstHand",
"Address" : "TTT RRR EEEE",
"Model" : "2018"
}
];
// First Way
var output1 = source.map((item) => ({
personName: item.personName,
CarName: item.CarName,
Price: item.Price,
Address: item.Address,
Model: item.Model
}));
console.log('Output1');
console.log(output1);
// Second Way
var output2 = source.map(({ personId, OwnerType, ...item }) => ({
...item
}));
console.log('Output2');
console.log(output2);
添加回答
举报