title: CodeMirror - "Cannot read property 'chunkSize' of undefined" when using replaceRange when iterating through an array with for...in
body: <p>(I realize that iterating through an array with numeric indexes with for...in is bad practice (<a href="https://stackoverflow.com/questions/500504/why-is-using-for-in-with-array-iteration-a-bad-idea">explained here</a>) but I do not see how this is relevant here. I would like to understand why the problem described below happens. I lack the experience and skill to read through the CodeMirror source code to find out what went wrong unfortunately.)</p>
  
  <p>Example app <a href="https://jsfiddle.net/c7kj1rbd/24//" rel="nofollow noreferrer">JSFiddle</a> </p>
  
  <p>There is a "2D array" generated here (array[]), 3 rows, each row consist of 4 elements (3 numbers and one \n character). My goal was to iterate through the whole "2D array" and put each character in the CodeMirror editor. </p>
  
  <ul>
  <li>If you click on the "for...in" button, the code will do the first two rows of the array, then drops the following error: </li>
  </ul>
  
  <p><code>Uncaught TypeError: Cannot read property 'chunkSize' of undefined</code></p>
  
  <ul>
  <li>If you click on the "for...in that works" button, you will get the right result with no errors. The only difference between this and the previous function is that the "line" argument of the replaceRange method has a +1. <strong>This way it works perfectly for some reason</strong></li>
  <li>if you click on the "forEach" button, everything will work fine</li>
  </ul>
  
  <p>I found about the fact that the "row" variable is the problem by trial and error. 
  So my questions are: </p>
  
  <ol>
  <li>Why do I get the error above with the "for...in" button?</li>
  <li>Why don't I get the error with the "for...in that works" button?</li>
  </ol>