I have 2 arrays of Objects;
// First one :
[0: {id: 1},
1: {id: 2},
2: {id: 3},
3: {id: 4}]
// Second one :
[0: {id: 10},
1: {id: 1},
2: {id: 4},
3: {id: 76},
4: {id: 2},
5: {id: 47},
6: {id: 3}]
I'd like to test if the second one has at least every same IDs of the first one. Which would be true in this case because the second one contains 1, 2, 3 and 4 IDs.
I tried to use some() and every() but it doesn't work properly
My try :
let res = this.trainingEpisodesList.some( episode => {
this.completedEpisodes.every( userEpisode => {
userEpisode.id == episode.id;
})
});
Thanks ;)
You can do this using every
and find
:
let completedEpisodes =
[
{id: 1},
{id: 2},
{id: 3},
{id: 4}
]
let trainingEpisodesList =
[
{id: 10},
{id: 1},
{id: 4},
{id: 76},
{id: 2},
{id: 47},
{id: 3}
]
let containsAllCompleted = trainingEpisodesList.every(c => completedEpisodes.find(e=>e.id==c.id));
console.log(containsAllCompleted);