title: Arrays - Javascript - filter array of objects using input search
body: <p>I am trying to filter a list using react, but surprisingly, for such a common task, cannot find anything online to help me achieve this.</p>
  
  <p>I have an array of users which I then want to filter through (starting off with name - I can work out filtering by age then). 
  The array is in my redux store and looks like the below.</p>
  
  <pre><code>let users = [
    {
      name: 'Raul',
      age: 29
    },
    {
      name: 'Mario',
      age: 22
    }
  ];
  </code></pre>
  
  <p>My entire component looks like the below.</p>
  
  <pre><code>class Test extends Component {
  
      constructor(props) {
          super(props);
  
          this.state = {
              users: this.props.users
  
          };
  
          this.filterList = this.filterList.bind(this);
  
      }
  
      componentWillReceiveProps(nextProps) {
  
          this.setState({
              users: nextProps.users
          });
  
      }
  
      filterList(event) {
  
          let users = this.state.users;
          users = users.filter(function(user){
          //unsure what to do here
          });
          this.setState({users: users});
      }
  
    render(){
  
      const userList = this.state.users.map((user) =&gt; {
        return &lt;li&gt;{user.name} {user.age}&lt;/li&gt;;
      });
  
      return(
        &lt;input type="text" placeholder="Search" onChange={this.filterList}/&gt;
        &lt;ul&gt;
          { userList }
        &lt;/ul&gt;
      );
  
    }
  }
  </code></pre>