Price closest to in array?
<p>I those 3 arrays in Javascript, the values in the array is ProductId => Price (xx:xx)</p>

<pre><code>var instantPriser = {11: 48,12: 96,13: 144,14: 192,15: 240,16: 288,17: 336,18: 384,19: 432,20: 480,21: 528,22: 576,23: 624,24: 672,25: 720,26: 768,9999999999999999};
var maletPriser   = {27: 20,28: 40,29: 60,30: 80,31: 100,32: 120,33: 140,34: 160,35: 180,36: 200,37: 220,38: 240,39: 260,40: 280,41: 300,42: 320,43: 340,44: 360,45: 380,46: 400,47: 420,48: 440,49: 460,50: 480,51: 500,52: 520,53: 540,54: 560,55: 580,56: 600,57: 620,58: 640,59: 660,60: 680,61: 700,62: 720,63: 740,64: 760,65: 780,66: 800,67: 820,68: 840,69: 860,70: 880,71: 900,9999999999999999};
var heleBoenner   = {72: 89,73: 178,74: 267,75: 356,76: 445,77: 534,78: 623,79: 712,80: 801,81: 890,82: 979,83: 1068,84: 1157,85: 1246,86: 1335,87: 1424,88: 1513,89: 1602,90: 1691,91: 1780,92: 1869,93: 1958,94: 2047,95: 2136,9999999999999999};
</code></pre>

<p>I am trying to see how i can get the closest "productId" from the array by my price?</p>

<p>I've tried this, but doesn't seem to work out very well:</p>

<pre><code> var price = 450;
 for ( i=0;i&lt;instantPriser.length;i++ ){
        if ( pris &lt;= instantPriser[i]){
            alert(instantPriser[i]);
            return false;
        }
 }
</code></pre>

<p>It should output like 19 or 20 because the values is 432 and 480 (closest to 450)</p>

<p>How can i do this?</p>
