Skip to content Skip to sidebar Skip to footer

Generate Array Of Numbers Between A Min And Max Value But Also With A Fix Interval Between 2 Values

I have the following data structure and I need to create an array of numbers that matches given configuration: { min: 1000, max: 10000, interval: 1000 } What would be a prop

Solution 1:

Using for loop, it can be done simply.

const input = {
  min: 1000,
  max: 10000,
  interval: 1000
};

const output = [];
for (let i = input.min; i <= input.max; i += input.interval) {
  output.push(i);
}
console.log(output);

Post a Comment for "Generate Array Of Numbers Between A Min And Max Value But Also With A Fix Interval Between 2 Values"