Skip to content Skip to sidebar Skip to footer

How To Arange List Of Numbers In Javascript?

In Python: data = range(50,60,2) print data [50, 52, 54, 56, 58] How can I do it in js? Looking for simple and shorter way. var range = (start, end) => [...Array(end - start

Solution 1:

You could write your own range function:

var range = function(start, stop, step){
      step = step || 1;
      var arr = [];
      for (var i=start;i<stop;i+=step){
         arr.push(i);
      }
      return arr;
};

Post a Comment for "How To Arange List Of Numbers In Javascript?"