title: Get max and min value from array in JavaScript
body: <p>I am creating the following array from data attributes and I need to be able to grab the highest and lowest value from it so I can pass it to another function later on.</p>
  
  <pre><code>var allProducts = $(products).children("li");
  prices = []
  $(allProducts).each(function () {
      var price = parseFloat($(this).data('price'));
      prices[price] = price;
  });
  console.log(prices[0]) &lt;!-- this returns undefined
  </code></pre>
  
  <p>My list items look like this (I have cut down for readability):</p>
  
  <pre><code>&lt;li data-price="29.97"&gt;&lt;a href="#"&gt;Product&lt;/a&gt;&lt;/li&gt;
  &lt;li data-price="31.00"&gt;&lt;a href="#"&gt;Product&lt;/a&gt;&lt;/li&gt;
  &lt;li data-price="19.38"&gt;&lt;a href="#"&gt;Product&lt;/a&gt;&lt;/li&gt;
  &lt;li data-price="20.00"&gt;&lt;a href="#"&gt;Product&lt;/a&gt;&lt;/li&gt;
  </code></pre>
  
  <p>A quick console.log on prices shows me my array which appears to be sorted so I could grab the first and last element I assume, but presently the names and values in the array are the same so whenever I try and do a prices[0], I get <em>undefined</em></p>
  
  <pre><code>[]
  19.38   19.38
  20.00   20.00
  29.97   29.97
  31.00   31.00
  </code></pre>
  
  <p>Got a feeling this is a stupidly easy question, so please be kind :)</p>