react filter list with given array code 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;