[SOLVED]-FILTERING VALUES FROM INSIDE ARRAY-REACTJS

FILTERING VALUES FROM INSIDE ARRAY-REACTJS

i think it will work with the array function some

selectedtags.length > 0 ? selectedtags.some(st => item.tag.includes(st)) : true

with this at least one selected tag should match the list of book tags and it will be displayed.

you are passing an array to includesincludes takes two arguments the first one is a value to check and the second is the position in the array (optional)

[1,2,3].includes(1) //true
[1,2,3].includes(1,3) //false

you need to check each element from tag at a time

const { tag } = book

for(let item of tag){
    if(list.includes(item)) return true
}
return false

your code should look like this

const filteredlist = booklist.filter(item => 
    (item.title.tolowercase().includes(searchtexthome)
    || item.author.tolowercase().includes(searchtexthome))

const result = selectedtags.length > 0 ? filteredlist.filter(x =>{
    const { tag } = x

    for(let item of tag) {
        if(selectedtags.includes(item)) return true
    }
    return false
}) : filteredlist
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments