title: Using for loop to add elements to an empty array
body: <p>I am trying to remove any duplicate from a JSON-like data list, so if there are two or more items with the same name, I just want to keep one.
  I am trying to solve it with this naive approach.
  And when I try to push the (data[i].name, data[i].age) to an empty array newData, the end result is just an empty array.
  But, if the array already had some value, it works.
  Here's the console:</p>
  <pre><code>[]  //this result is with empty array
  (9) [1, &quot;player1&quot;, 10, &quot;player2&quot;, 30]  //this result is with newData.push(1);
  </code></pre>
  <p>Here the code</p>
  <pre><code>function someFunction(data) {
      const newData = [];
      newData.push(1);
      
        for (var i = 0; i &lt; data.length; i++) {
          for (var j = 0; j &lt; newData.length; j++) {
            if (i !== j) {
              if (!newData.includes(data[i].name)) {
                newData.push(data[i].name, data[i].age);
              }
            }
          }
        }
      
        return newData;
  }
  </code></pre>
  <p>lets say I have a data list like this:</p>
  <pre><code>const data = [
   {
    name: &quot;player1&quot;,
    score: 10
   },
   {
    name: &quot;player2&quot;,
    score: 30
   }, 
  {
    name: &quot;player1&quot;,
    score: 10
   },
  ]
  </code></pre>
  <p>Can someone help to explain?
  And I came up with this idea on my own, I know I can use something like array.reduce() or a  hashmap, but I really want to know if I can do it this way.
  Also, is there any way that I can push (data[i].name, data[i].age) to the array as one element? I think I am adding two at one iteration.
  Thank you!</p>