title: Array Pattern using Javascript
body: <p>I have an array: <code>Myarray=[1,0,0,1,0,1,1,0,0]</code></p>
  
  <p>I want to display the elements of the array in the pattern 1,0,1,0..</p>
  
  <p>I tried to set a flag:</p>
  
  <pre><code>for (var i = 0; i &lt; myArray.length; i++) {
    if (myArray[i] == flag) {
      newArray = newArray + myArray[i];
      if (flag == 0)
        flag = 1;
      else
        flag = 0;
    }
  </code></pre>
  
  <p>But the problem is the mismatched elements are not showing in output.</p>
  
  <p>Any Idea? Thanks.</p>