Thursday, July 3, 2014

Initialize JavaScript Array with series of numbers

<button onclick="init()">Initialize array</button>
<script>
function init() {
    var numbers = [];
    for(var i=1; numbers.push(i++)<20;);

    alert(numbers);
}
</script>

No comments:

Post a Comment