title: Is for (let i in string) {} equivalent to for (let i = 0; i < string.length; i++) {}?
body: <p>I have two pieces of code I wrote, I suppose they should work the same. As you may notice the only thing which is different between the two is the declaration of the for-loop.</p>
  
  <p>Why is the code with for-in not working as expected?</p>
  
  <p>Thanks in advance.</p>
  
  <pre><code>const allPermutations1 = s =&gt; {
       let permutations = []
  
       const recursion = (s, p = '') =&gt; {
  
           if (s.length === 0) return permutations.push(p)
  
           for (let i = 0; i &lt; s.length; i++)
               recursion(s.slice(0, i) + s.slice(i+1), p + s[i]) 
       }
  
       return (recursion(s), permutations)
   }
  
  allPermutations1('123') // ["123", "132", "213", "231", "312", "321"]
  
  const allPermutations2 = s =&gt; {
      let permutations = []
  
      const recursion = (s, p = '') =&gt; {
  
          if (s.length === 0) return permutations.push(p)
  
          for (let i in s)
              recursion(s.slice(0, i) + s.slice(i+1), p + s[i]) 
      }
  
      return (recursion(s), permutations)
  }
  
  allPermutations2('123') // ["123", "132", "21", "312", "321"]
  </code></pre>