title: The end of my for loop is not running in my javascript function
body: <p>I am trying to recreate the indexOf function in JavaScript. I can not get the return -1 portion to work, but the other parts work fine. It seems like the end of my for loop is not running, as I try to print out &quot;end of loop&quot;. I have some test code as well and the outputs below. Any help would be appreciated.</p>
  <pre><code>Array.prototype.myIndexOf = function(...args) {
      if(args[1] === undefined){
          for(let i = 0; i &lt; this.length; i++){
              if(this[i] === args[0]){
                  return i;
              }
          }
      } else {
          for(let i = args[1]; i &lt; this.length; i++){
              if(this[i] === args[0]){
                  return i;
              }
          }
          console.log(&quot;end of loop&quot;)
          return -1;
      }
  };
  
  // TEST
  
  const beasts = ['ant', 'bison', 'camel', 'duck', 'bison'];
  
  console.log(beasts.indexOf('bison'));
  console.log(beasts.myIndexOf('bison'));
  // expected output: 1
  
  // start from index 2
  console.log(beasts.indexOf('bison', 2));
  console.log(beasts.myIndexOf('bison', 2));
  // expected output: 4
  
  console.log(beasts.indexOf('giraffe'));
  console.log(beasts.myIndexOf('giraffe'));
  // expected output: -1
  
  </code></pre>
  <pre><code>1
  1
  4
  4
  -1
  undefined
  </code></pre>