get numbers between two numbers javascript code example

Example 1: random int between two numbers javascript

// Between any two numbers
Math.floor(Math.random() * (max - min + 1)) + min;

// Between 0 and max
Math.floor(Math.random() * (max + 1));

// Between 1 and max
Math.floor(Math.random() * max) + 1;

Example 2: js difference between two numbers

var difference = function (a, b) { return Math.abs(a - b); }

Example 3: javascript range of integers

// n is your max range
[...Array(n).keys()]

let n = 10
[...Array(n).keys()] // [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

Example 4: javascript range of integers

var list = [];
for (var i = lowEnd; i <= highEnd; i++) {
    list.push(i);
}