Get max or min value from associative array with function and parameters
<p>Here is the code as far as I got it right now:</p>

<pre><code>&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;body&gt;

&lt;button onclick="scanarray('a', 'max')"&gt;Test with a, max&lt;/button&gt;

&lt;button onclick="scanarray('b', 'min')"&gt;Test with b, min&lt;/button&gt;



&lt;p id="demo"&gt;test&lt;/p&gt;

&lt;script&gt;



var array = [{"a":1},{"b":3},{"a":6},{"b":10}];


var max = null;
var min = null;
var value = null;

function scanarray(scanval, searchterm) {

  if (array.length &lt; 1) {
    return -1;
  }

    if(searchterm == "max"){

    max = Math.max.apply(Math,array.map(function(e){return e.scanvalue;}))

    }else if (searchterm == "min"){

    min = Math.min.apply(Math,array.map(function(e){return e.scanval;}))

}else
{document.getElementById("demo").innerHTML = "Only max and min available";}

    if(searchterm == "max"){

        document.getElementById("demo").innerHTML = "Search: " + scanval +"  "+ "Value: " + max;
    }

    if(searchterm == "min"){
        document.getElementById("demo").innerHTML = "Search: " + scanval +"   "+ "Value: " + min;
    }

}
&lt;/script&gt;

&lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>The above should give me a and 6 or b and 3 as results. However I get NaN as result for the value part. When using "return e.a" in the Math section and only having a as keys it works. </p>

<p>I want to be able to determin the max or min value of a key I enter as parameter to the function.</p>

<p>Hope you can help me here. </p>

<p>Thanks in advance.</p>

<p>TheVagabond</p>