I have an array like:
const property = [ {name: Demo}, {name: Test}]
const I also Have a state for search Value
const [searchText,setSearchText] = useState('')
whenever the search Text Change I am firing a useEffect()
useEffect(() => {
//Do Something
},[searchText])
What I wanna do is to filter out the value of the property array based on the searchText.
useEffect(() => {
const data = property.filter(el => el.name === searchText)
console.log(data).
},[searchText])
But by doing this way we have to write exact same name in the search box to filter out the value
like:
useEffect(() => {
const data = property.filter(el => el.name === searchText) // In here the el.name need to be exact the searchText value in order to filter the array
console.log(data).
},[searchText])
I want if someone types a letter like "b" then filter out all the result except which one has starts with "b". If anyone writes "The" then I wanna filter out all the value except which one has "The"