react-native array.filter syntax example
Example 1: filter array react
<div>
{people.filter(person =>
person.age < 60).map(filteredPerson => (
<li>
{filteredPerson.name}
</li>
))}
</div>
Example 2: react filter
import React from 'react';
const people = [
{
name: 'James',
age: 31,
},
{
name: 'John',
age: 45,
},
{
name: 'Paul',
age: 65,
},
{
name: 'Ringo',
age: 49,
},
{
name: 'George',
age: 34,
}
];
function App() {
return (
<div>
{people.filter(person => person.age < 60).map(filteredPerson => (
<li>
{filteredPerson.name}
</li>
))}
</div>
);
}
export default App;
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 })
}