title: How to avoid adding to an array if element already exists
body: <p>I'm making Add to favorite function in React. Thanks to everyone's help I could somehow make that work except for toggling like and dislike. I coded like "likes: this.state.likes.filter(e => e.name !== person.name)" just because someone advised me to code so. To be honest I don't understand the code above maybe because it's ES6 syntax. How does it look like in ES5? And right now that code is not working, elements are not added to the array properly. How do I fix this code?</p>
  
  <pre><code>import React from 'react';
  import axios from 'axios';
  import IcoMoon from 'react-icomoon';
  
  export default class PersonList extends React.Component {
  
      state = {
          persons: [],
          likes: []
      }
  
      componentDidMount() {
          axios.get(`https://jsonplaceholder.typicode.com/users`)
              .then(res =&gt; {
                  const persons = res.data;
                  this.setState({ persons });
              })
      }
  
      handleClick = person =&gt; {
  
          if (this.state.likes.filter(e =&gt; e.name === person.name).length &gt; 0) {
  
              this.setState({
                  likes: this.state.likes.filter(e =&gt; e.name !== person.name)
              });
  
              console.log(this.state.likes);
              return;
          }
  
          this.setState({
              likes: [...this.state.likes, person]
          });       
      };
  
      likesTemplate = item =&gt; &lt;li key={item}&gt;{item}&lt;/li&gt;;
  
      renderLikes = () =&gt; {
          return this.state.likes.map(i =&gt; this.likesTemplate(i));
      }
  
      render() {
          return (
              &lt;div&gt;
                  {this.state.persons.map(person =&gt; {
                  return &lt;li key={person.name}&gt;&lt;IcoMoon icon="heart" onClick={() =&gt; {this.handleClick(person.name)}} /&gt;{person.name}&lt;/li&gt;}
              )}
  
              &lt;h2&gt;Favorite Person&lt;/h2&gt;
              &lt;ul&gt;
                  {this.renderLikes()}
              &lt;/ul&gt;
              &lt;/div&gt;
          )
      }
  }
  </code></pre>