Last Updated: February 25, 2016
·
1.364K
· james2doyle

Array.prototype.range

Array.prototype.range = function(a, b, step) {
    step = !step ? 1 : step;
    b = b / step;
    for(var i = a; i <= b; i++) {
        this.push(i*step);
    }
    return this;
};

var myarray = [];
myarray.range(0, 10, 2); // returns 0, 2, 4, 6, 8, 10

Have a fresh tip? Share with Coderwall community!

Post
Post a tip
Did you know?

JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.

Security insights from Cside