Incremental loop between ranges in JavaScript

3

I have the following Array's (below), and I need to print in increments the ranges of positions that are there, I mean, in position 0 of array1 is the 10 and in array2 is the 15, I need to increase in one and then start from the number that is in position 1 of the array1 example:

var miArray = [ 10, 20, 40, 65 ];
var miArray2= [15, 26, 44, 71];

this should print me:

10,11,12,13,14,15,20,21,22,23,24,25,26,40,41,42,43,44,65,66,67,68,69,70,71

I wanted to try some examples that I searched the Internet but I do not even approach it.

    
asked by Rafael Pereira 14.08.2018 в 17:49
source

1 answer

3

You only need two for nested like this:

var miArray = [ 10, 20, 40, 65 ];
var miArray2= [15, 26, 44, 71];

for (var i=0; i<miArray.length; i++) {  
  for (var j=miArray[i]; j<=miArray2[i]; j++) {
    console.log(j);
  }
}
    
answered by 14.08.2018 / 17:54
source