I have an array classTopics
where an object looks like this:
{
questions:2,
id:49,
topic:{
edited: null
id: 1
name: "Topic name"
status: "ACTIVE"
topicCode:"02"
}
}
And I also have an array allTopics
where the objects are the same as topic property in the example above:
{
edited: null
id: 1
name: "Topic name"
status: "ACTIVE"
topicCode:"02"
}
In the select field I would like to filter all the topics that are the same as a property topic
in the objects of the classTopics
array.
So, something like this:
<AutoCompleteSelect
options={allTopics.filter(topic => !classTopics.includes(topic)).map(({name}) => ({value: name, label: name}))}
/>
But, that is not working since it is checking the objects as a whole. How can I do something similar where I could check it against the property on the object?
Basically what I am trying to achieve is this in a nicer way:
const filteredTopics = allTopics
.filter(topic =>
(classTopics.findIndex(classTopic => classTopic.topic.id === topic.id)) === -1);
You can find the working example here.