我有一个对象包含许多键值对记录的JSON数组,但是我只需要几个键记录。如何使用键创建新数组?

array = [
{
 airlineName: "Airline 1",
 hotelName: "Hotel 1 ",
 airportId: "456",
 checkInDate: "17 SEP 1998",
 bookingStatus: "B"
},
{
airlineName: "Airline 2",
 hotelName: "Hotel 1",
 airportId: "123",
 checkInDate: "7 AUG 1998",
 bookingStatus: "P"
 }
]


我想要这样的数组进行一些操作:

array = [
{
 airlineName: "Airline 1",
 hotelName: "Hotel 1 ",
 bookingStatus: "B"
},
{
airlineName: "Airline 2",
 hotelName: "Hotel 1",
 bookingStatus: "P"
 }
]

最佳答案

单线工作解决方案:

this.array.map(x => ({airlineName: x.airlineName, hotelName: x.hotelName, bookingStatus: x.bookingStatus}))

07-28 07:21