I have a array that I fetched from git HUB api,
[{
id: 362784382,
imageURL: "https://raw.githubusercontent.com/CRISTIAN-MULLER/BookShelf-Backend/main/Tela.png",
name: "BookShelf Backend" ,
ownerName: "CRISTIAN-MULLER",
topics: ["javascript","reactjs"]
},
{
id: 362784383,
imageURL: "https://raw.githubusercontent.com/CRISTIAN-MULLER/BookShelf-
Backend/main/Tela.png",
name: "BookShelf" ,
ownerName: "CRISTIAN-MULLER",
topics: ["other tag","react"]
}
]
This data has tags with languages that I used in My projects,
In another part of my code i have a function that iterates trough this array and returns a array of tags with unique names.
const topicsWithoutDuplicates = [...new Set(topics.flat())].map((elem) => ({
id: elem,
title: elem,
}));
I render for each element a button im My portfolio page, and I need to when i click a button , iterate all data and return only the projects that has the topic matching the button ID,
I'm trying to construct a function that do this, but I'm stuck, "selected" has an array of strings with the buttons pressed ["javascript", "react", ....],
I know that includes Method receives only strings as arguments and thats way this is not working, so I need to get the "selected" array and for each, item iterate over the received data from github and return only the elements that has in topics the same name that I have in selected array.
so basicaly i need to iterate an array over another array comparing each element.
const filteredData = userData.filter((item) =>
item.topics.map((topic) =>
topic.includes(selected)
)
);
How can I do that?, I'm not thinking anymore.