title: Looping through elements of an array in Javascript
body: <p>I have an array in Javascript:</p>
  
  <pre><code>var array = new array();
  array[0] = "apples";
  array[1] = "oranges";
  array[2] = "pears";
  </code></pre>
  
  <p>In PHP, with a given array, I can use the following to loop through an array, and break up the keys and values:</p>
  
  <pre><code>foreach ($array as $key =&gt; $value) {
      echo("Key is $key and Value is $value");
  }
  </code></pre>
  
  <p>How can I do this in Javascript? I'm aware of:</p>
  
  <pre><code>for (x in array){
      // Do something with x.
  }
  </code></pre>
  
  <p>But I've found nothing that will replicate the php style foreach. Is it possible to concisely achieve something similar in Javascript? (I'm also using jQuery, if something can be done in jQuery).</p>