title: Printing out all duplicates - Javascript - Alternate solution needed
body: <p><strong>INSTRUCTIONS</strong></p>
  
  <p><code>Given an array, print out all of the duplicates within that array.</code></p>
  
  <pre><code>let arr = [1, 2, 2, 3, 3, 4, 5, 5, 8, 8, 9, 10];
  
  const result = arr.filter(x =&gt; arr.filter(y =&gt; y === x).length &gt; 1);
  
  console.log(result);
  
  // 2, 2, 3, 3, 5, 5, 8, 8
  </code></pre>
  
  <p>So, someone else kindly provided this answer, which I understand, but I'm looking for alternate solution that uses for-loops instead. </p>
  
  <p>I came up with this, but this only returns</p>
  
  <p><code>2, 3, 5, 8</code> instead of the above results that I need.</p>
  
  <pre><code>const result2 = () =&gt; {
    let newArray = [];
  
    for(let i = 0; i &lt; arr.length; i++) {
      if(arr[i] === arr[i + 1]) {
        newArray.push(arr[i])
      }
    }
     return newArray
  }
  
  console.log(result2(arr));
  
  // 2, 3, 5, 8
  </code></pre>
  
  <p>What am I missing? I need for it to print out all duplicates, not just tell me which ones are duplicates.</p>