I want to filter the second array, cards, so that it only shows records specified in the cardsfFilter array which is in the first object ( id=1) in the groups.cardsFilter array
ARRAYS AND REQUIRED RESULT ARE BELOW
const groups = [
{
id: 1,
name: 'Melbourne Bands',
//Below is the array that I need to act as the filter for the cards array
cardsFilter: [1, 2]
},
{
id: 2,
name: 'Sydney Bands',
cardsFilter: [3]
}
]
const cards = [
{
id: '1',
url: 'jimmyyukka.com',
name: 'Jimmy Yukka',
CreatedByUserId: 1
},
{
id: '2',
url: 'jimmyyukka.com',
name: 'Due North',
CreatedByUserId: 1
},
{
id: '3',
url: 'jimmyyukka.com',
name: 'INXS',
CreatedByUserId: 1
}
]
const desiredResult = [
{
id: '1',
url: 'jimmyyukka.com',
name: 'Jimmy Yukka',
CreatedByUserId: 1
},
{
id: '2',
url: 'jimmyyukka.com',
name: 'Due North',
CreatedByUserId: 1
},
]
I am struggling to figure it out and can't find an example on stack overflow for this simple approach.
I HAVE TRIED (one record) I can't figure out how to do this with the array
const notQuiteRight= cards.filter(function(getFile){
return getFile.id === "1"
});