title: Compare 2 array's elements against each other and return count JavaScript
body: <p>I have 2 arrays that I need to compare against each other and return the count of the same.</p>
  
  <p>Example: compare array1 [abcd] against array2 [adce]. Return would be 2,1 as both a and c are in same position and d is in the wrong position. </p>
  
  <pre><code>function () {
      var index = 0;
      for (index = 0; index &lt; length; index++) {
          if (array1[index] == array2[index]) {
              count++
          } 
      }
      return count
  }
  </code></pre>
  
  <p>I'm getting a return of 1. I think that's because they equal in length that is why I'm getting a 1. So I'm thinking that I now need to put another <code>for</code> loop and have that loop go through the elements individually, but not sure how to do this. I could be completely wrong in what I have put above, if so, could someone explain the process to me please.</p>