Problem link: https://stackoverflow.com/questions/55905395/search-with-tags-using-includes
Use array.filter(item => item.tag.some(checkTag)).map(item => item.name)
> let array = [
... {
... "name": "CoffeShop",
... "tag":[
... "Coffee",
... "Cookies",
... ],
... },
... {
... "name": "TeaShop",
... "tag":[
... "Tea",
... ],
... },
... {
... "name": "IceCreamShop",
... "tag": [
... "Ice Cream",
... ]
... },
... ]
undefined
>
> let tags = ['Coffee', 'Cookies']
undefined
>
>
> function checkTag(tag) {
... return tags.indexOf(tag) > -1
... }
undefined
>
> array.filter(item => item.tag.some(checkTag))
[ { name: 'CoffeShop', tag: [ 'Coffee', 'Cookies' ] } ]
>
> array.filter(item => item.tag.some(checkTag)).map(item => item.name)
[ 'CoffeShop' ]
>
>