Я пытаюсь отфильтровать объекты, которые содержат строку среди его массива. У меня есть это внутри массива объектов.
У меня есть это:
[
{
articles: {
id: "1",
title: "Great food article",
featured: false,
paid: false,
image: img1,
author: "Chocolate Boy",
date:"1-2-2020",
description:
"Street art edison bulb gluten-free, tofu try-hard brooklyn tattooed pickled chambray. Actually humblebrag next level, deep v art party wolf tofu direct trade readymade sustainable hell of banjo. Organic authentic subway tile cliche palo santo, street art XOXO dreamcatcher retro sriracha portland air plant kitsch stumptown. Austin small batch squid gastropub. Pabst pug tumblr gochujang offal retro cloud bread bushwick semiotics before they sold out sartorial literally mlkshk. Vaporware hashtag vice, sartorial before they sold out pok pok health goth trust fund cray.",
tags: [
"Tech",
"Food"
]
}
},
{
articles: {
id: "2",
title: "Good tech article",
featured: false,
paid: false,
image: img2,
author: "Candy Boy",
date:"1-2-2020",
description:
"Street art edison bulb gluten-free, tofu try-hard brooklyn tattooed pickled chambray. Actually humblebrag next level, deep v art party wolf tofu direct trade readymade sustainable hell of banjo. Organic authentic subway tile cliche palo santo, street art XOXO dreamcatcher retro sriracha portland air plant kitsch stumptown. Austin small batch squid gastropub. Pabst pug tumblr gochujang offal retro cloud bread bushwick semiotics before they sold out sartorial literally mlkshk. Vaporware hashtag vice, sartorial before they sold out pok pok health goth trust fund cray.",
tags: [
"Tech",
"Adventure"
]
}
},
{
articles: {
id: "3",
title: "Nice adventure article",
featured: false,
paid: false,
image: img3,
author: "Lollypop Boy",
date:"1-2-2020",
description:
"Street art edison bulb gluten-free, tofu try-hard brooklyn tattooed pickled chambray. Actually humblebrag next level, deep v art party wolf tofu direct trade readymade sustainable hell of banjo. Organic authentic subway tile cliche palo santo, street art XOXO dreamcatcher retro sriracha portland air plant kitsch stumptown. Austin small batch squid gastropub. Pabst pug tumblr gochujang offal retro cloud bread bushwick semiotics before they sold out sartorial literally mlkshk. Vaporware hashtag vice, sartorial before they sold out pok pok health goth trust fund cray.",
tags: [
"Tech",
"Food",
"Adventure"
]
}
},
]
Я хочу вернуть оба объекта, которые содержат "food" в их массиве "tags" Если я сравниваю строка "food".
filterArticles = () =>{
let{
articles, tags
} = this.state
let tempArticles = [...articles];
console.log(tempArticles)
//Making array of arrays of articles tags
let array1 = [...new Set(tempArticles.map(item => item["tags"]))];
//Making the array of arrays flat to one dimensional array
let array2 = [...new Set(array1.flat(1))];
console.log(array2)
console.log(tags)
}
Где tempArticles имеет все 3 объекта, а теги имеют значение food, но он возвращает только массив всех 3 тегов в массиве.
Ожидается 1 и 3 объекта.
Помощь с объяснением оценена, поскольку я пытаюсь выяснить это некоторое время.