1 回答
TA贡献1793条经验 获得超6个赞
let arr =
[
{
id: 1,
name: "A",
watched: [
{movieId: 7, movieName: "Avatar"} ,
{movieId: 8, movieName: "Titanic"}
]
},
{
id: 2,
name: "B",
watched: [
{movieId: 1, movieName: "Armageddon"} ,
{movieId: 8, movieName: "Titanic"}
]
},
{
id: 3,
name: "C",
watched: [
{movieId: 1, movieName: "Armageddon"} ,
{movieId: 7, movieName: "Avatar"}
]
}
];
let result = arr.map((item, index) => ({...item, index}))
.filter(item => item.watched.find(watchedItem => watchedItem.movieName === 'Avatar'))
.map(item => item.index);
console.log('expected result', result);
添加回答
举报