Underscore.js has a range()
function. Is that what you want?
http://underscorejs.org/#range
You could do something like:
var RANGE_DISTANCE = 3;
var CENTER = 19;
_.range(CENTER - RANGE_DISTANCE, CENTER + RANGE_DISTANCE + 1)
Which you could abstract out to a function:
function generateRangeAroundCenter(var center, var range_distance) {
return _.range(center-range_distance, center+range_distance+1);
}
Seems like overkill to import underscore just for that though.
I see some good examples of what you want here:
Does JavaScript have a method like "range()" to generate an array based on supplied bounds?
There are examples that don't use libraries at all, like this. Let me know if that helps you out, or if you're looking for something else.