I have two arrays, one with existing tags of book and another with searched results by user input value of tag to add and I need to show user tags to add that doesn't already exist in tags:
tags = [{id:1, name:'x'},{id:2, name:'y'},{id:5, name:'z'}]
search = [{id:2, name:'y'},{id:5, name:'z'},{id:15, name:'s'}]
How can I make a new array that will have search id's and other data that doesn't exist in tags array?
This is how it's worked for me in the end:
let newArray= search
.filter(({ id }) => {
return !tags.some(tag => {
return tag.id == id
})
})
.map(tag => {
return (
<Button
key={tag.id}
>
{tag.name}
</Button>
)
})