I have an array of cards. And I need to filter it by value word based on another array. only those objects should remain in cards that correspond to the names in the array difficultWords
const cards = [
{
word: 'cry',
},
{
word: 'fishing',
},
{
word: 'fly',
},
{
word: 'hug',
},
],
[
{
word: 'open',
},
{
word: 'play',
},
{
word: 'run',
},
{
word: 'sing',
},
],
.....
let difficultWords = ["cry", "run", "sing"];
That's my code: (but id doesn't work)
let wrongCard = cards.forEach(card => {
card.filter(el => difficultWords.forEach(i => el.word === i));
}
The output should be
let wrongCard = [
[
{
word: 'cry',
},
],
[
{
word: 'run',
},
{
word: 'sing',
},
]