How can I get the minimum value from an array in JavaScript? I did try the Math.min method and it seems that it doesn't work as expected.
As an example, I have four divs with numeric values:
HTML:
<div id="r">3121</div>
<div id="g">2334</div>
<div id="b">3445</div>
<div id="a">4121</div>
JavaScript:
var r = $('#r').text(),
g = $('#g').text(),
b = $('#b').text(),
p = $('#a').text();
var mainBox = [r,g,b,a];
var minN = Math.min(mainBox);
alert(minN);
Can you please tell me what am I doing wrong?