我具有以下结构的JavaScript对象数组:
var arrayObj = [
{
"Rank": 1,
"Title": "The Shawshank Redemption",
"Description": "Two imprisoned men bond over a number of years, finding solace and eventual redemption through acts of common decency.",
"Runtime": 142,
"Genre": "Crime",
"Rating": 9.3,
"Metascore": 80,
"Votes": 1934970,
"Gross_Earning_in_Mil": 28.34,
"Director": "Frank Darabont",
"Actor": "Tim Robbins",
"Year": 1994
},
{
"Rank": 2,
"Title": "The Godfather",
"Description": "The aging patriarch of an organized crime dynasty transfers control of his clandestine empire to his reluctant son.",
"Runtime": 175,
"Genre": "Crime",
"Rating": 9.2,
"Metascore": 100,
"Votes": 1323670,
"Gross_Earning_in_Mil": 134.97,
"Director": "Francis Ford Coppola",
"Actor": "Marlon Brando",
"Year": 1972
}]
我想从除“导演”之外的每个对象中提取一个字段,并获取一个包含值的数组,例如
[[1,
'The Shawshank Redemption',
'Two imprisoned men bond over a number of years, finding solace and
eventual redemption through acts of common decency.',
142,
'Crime',
9.3,
80,
1934970,
28.34,
'Tim Robbins',
1994 ],
[ 2,
'The Godfather',
'The aging patriarch of an organized crime dynasty transfers control
of his clandestine empire to his reluctant son.',
175,
'Crime',
9.2,
100,
1323670,
134.97,
'Marlon Brando',
1972 ]]
答案 0 :(得分:1)
您可以通过分解并使用其余属性来排除键。
var array = [{ Rank: 1, Title: "The Shawshank Redemption", Description: "Two imprisoned men bond over a number of years, finding solace and eventual redemption through acts of common decency.", Runtime: 142, Genre: "Crime", Rating: 9.3, Metascore: 80, Votes: 1934970, Gross_Earning_in_Mil: 28.34, Director: "Frank Darabont", Actor: "Tim Robbins", Year: 1994 }, { Rank: 2, Title: "The Godfather", Description: "The aging patriarch of an organized crime dynasty transfers control of his clandestine empire to his reluctant son.", Runtime: 175, Genre: "Crime", Rating: 9.2, Metascore: 100, Votes: 1323670, Gross_Earning_in_Mil: 134.97, Director: "Francis Ford Coppola", Actor: "Marlon Brando", Year: 1972 }],
result = array.map(({ Director, ...o }) => o);
console.log(result);