0

I have data in array

var dataArray = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, ... , 998, 999, 1000];

if i want to select data to show 10 times in each time I want to show 100 data in arrays

First time show output

1, 2, 3, 4, 5, 6, 7, 8, 9, 10 , ..., 100

Second time show output

101, 102, 103, 104, 105 , ..., 200

.

.

.

tenth time show output

901, 902, 903, 904, 905, ..., 1000

Which function can help me or other way can help me (Node Js)?

1

3 Answers 3

1

please try this code and feel free to adapt it according to your NodeJS requirements.

Best,

//Init array
var initArray = function(count){
  var res = [];
  for (var i = 0; i < count; i++) {
    res.push(i+1);
  }
  return res;
};

var myArray = initArray(1000);


var idx = 0, cutVal = 100;

var showMe = function(){
  var print = '';
  for (var i = idx; i < (idx + cutVal); i++) {
    print = print + myArray[i] + ', ';
  }
  console.log(print);
  idx = idx + cutVal;
};
showMe();
showMe();
showMe();
Sign up to request clarification or add additional context in comments.

Comments

1

let sidx = 0;
let size = 100;
let results = [];
function divide() {
    for(let i = sidx; i < (sidx + size) && i < dataArray.length; i++){
        results.push(data[i]);
    }
    sidx += size;
    //showData of result
    process.nextTick(divide);
}
or you can use setTimeout instead of process.nextTick

Comments

0

const p = (arr, n) => {
  let portion, start = 0;
  while ((portion = arr.slice(start, start + n)).length) {
    console.log(portion.join(','));
    start += n;
  }
};

const inputA = Object.keys([...Array(30)]);
p(inputA, 10);

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.