My problem is that I want to find the category of the every title movie that I want to search. For example
searchInput = Action
outputShown = [Transformer,Dinosaur, Godzilla]
Since I have category that listed as you see below:
const category = ['Comedy','Classic','Drama','Romance','Science-
Fiction','Adult','Sex','Kids','Animation','Cartoon','Action','Storyline','Tragic']
I wanted this TitleItems to have match to my searchinput even if they have different type of category.
const TitleItems = {
imgPath:'', name:'The Office',type:['Comedy','Classic','Romance'],views:"5666",rate:"4.1"
},
{
imgPath:'', name:'Ready Player One',type:['Science-Fiction','Romance','Drama'],views:"7776",rate:"4.2"
},
{
imgPath:'', name:'Interstellar',type:['Science-Fiction','Drama','Romance','Tragic'],views:"10505",rate:"4.5"
},
{
imgPath:'', name:'Transformer',type:['Science-Fiction','Action','Classic','Comedy'],views:"20015",rate:"4.3"
},
{
imgPath:'', name:'Jack N The Giant',type:['Science-Fiction','Action','Adult','Comedy'],views:"12234",rate:"4.2"
}
As you see this is the searchinput, my only problem here is item.type, Since it have an array
I cannot do it as item.type.toLowerCase().includes(search.toLowerCase()), but I can do it as item.type[0].toLowerCase().includes(search.toLowerCase()) because it cannot include a array but what I really wanna do it must be search in that array of every item type of the title. So I wonder how's that gonna work? Anyone idea? I don't know if I ask the right question. Please edit it for me if it's a terrible question.
const [search,setsearch] = useState("");
const ListItems = items.filter((item,index) => {
return (
item.name.toLowerCase().includes(search.toLowerCase()) ||
item.views.toLowerCase().includes(search.toLowerCase()) ||
item.rate.toLowerCase().includes(search.toLowerCase()) ||
item.type.toLowerCase().includes(search.toLowerCase())
)
}).map((item,index) => {
return(
<div>
<h1 key={index}>
{item.name}, {item.type} {item.views} {item.rate}
</h1>
</div>
)
})
And here is the body to show the output
<input type="text" name='search' placeholder='Search...' value={search} onChange={e => setsearch(e.target.value)} />
{ListItems}