How to store Unique data and increment the Ratio using a JavaScript Array <p>I want to store a <code>random</code> generated data that looks like <code>1-2-3-4-5-6</code> using a <code>javascript array</code>.</p> <p>Each data may contain only the <code>-</code> character and 6 unique numbers from <code>1</code> to <code>49</code>.</p> <p>I declared the array as: <code>var a = new Array();</code></p> <p>Each time a new data is being generated, I store it like: <code>a[data] = 1;</code> where <code>data</code> might be <code>2-36-33-21-9-41</code> and <code>1</code> represents the ratio;</p> <p>If the data generated already exists, I must increment the ratio, like: <code>a[data]++;</code></p> <p>Why is the <code>length</code> property not available?</p> <p>I need to refresh the <code>length</code> value on the page each time a new unique data has been generated, maybe at each 1 millisecond.</p> <p>I can't parse a 1 million array that fast ... each time ...</p> <p>this is how i insert or update:</p> <pre><code>if (variante_unice[s]) { variante_unice[s]++; } else { variante_unice[s] = 1; variante_unice_total++; } </code></pre> <p>the code:</p> <pre><code> window.setInterval( function() { variante++; $("#variante").text(variante); for (j = 1; j &lt;= 49; j++) { $("#v" + j).attr("class", ""); } for (j = 1; j &lt;= 49; j++) { extracted[j] = 0; } ind = 0; s = ''; while (ind &lt; 6) { r = Math.floor((Math.random() * 49) + 1); if (extracted[r] == 0) { //this is where i generate the data if (s === '') { s = r; } else { s += '-' + r; } //console.log(r); extracted[r] = 1; frecvency[r]++; $("#n" + r).attr("class", "green"); $("#v" + r).attr("class", "green"); ind++; //console.log('i'+frecventa[r]); frecventa[r]++; //console.log('d'+frecventa[r]); $("#f" + r).text(frecventa[r]); } } //is the generated data new? if not, increment ratio if (variante_unice[s]) { variante_unice[s]++; } else { variante_unice[s] = 1; variante_unice_total++; } //console.log(variante_unice); //console.log(variante_unice[s]); //console.log(variante_unice.length); //console.log(s); verifica_varianta(); //console.log(extracted); //console.log(frecvency); } , 1); </code></pre>