reactjs filter array of objects code example

Example 1: filter array react

<div>
  {people.filter(person => 
    person.age < 60).map(filteredPerson => (
    <li>
      {filteredPerson.name}
    </li>
  ))}
</div>

Example 2: react js filter array of on search

use .include array function

{names.filter(name => name.includes('J')).map(filteredName => (
  <li>
  {filteredName}
  </li>
))}

Example 3: filter() array of objects on change react

const handleChange = (e) => {
      const id = hospitalsDetails.filter(obj => obj.hospitalName == e.target.value)
      setCurrentApp({ ...currentApp, [e.target.id]: e.target.value, ["hospitalID"]: id.hospitalID })  
}

Example 4: render a list using array filter react

react rendering using array.filter