0

I have 22 arrays and each array have a 1000 elements, what I need is to concat all those 22 arrays into one without losing data.

I already tried this options and all of them gave me the same result, which is losing data.

    var final_result = [];
    var result2 = [];
    var result = page_identifier.map(({ identifier }) => identifier); 

    final_result.extend(result);
    Array.prototype.push.apply(final_result,result);
    final_result = final_result.concat(result);
    var final_result = result2.concat(result);

result is the result of an Axios request and that request retrieve 1000 elements per request and its call 22 times. that's why final result should have a length of 22000 elements but right now it only have 502.

Does someone knows what this happens and how to fix it? Thanks.

This is the entire code

  var pages = 22;
  var page = 0;
  while (page != pages) {

    sails.log(`Getting page number ${page} of ${pages}`)

    var identifier_axios = {
      method: "get",
      url: `https://${address}///page=${page}`,
      proxy: false,
    };

    var res_identifier = await axios(identifier_axios);
    var page_identifier = res_identifier.data.resourceList;

    var final_result = [];
    var result = page_identifier.map(({ identifier }) => identifier); 

    console.log("result length", result.length, "of page", page);
    Array.prototype.push.apply(final_result,result);

    page++;
  }

  console.log("final_result",final_result);
  console.log("final_result length", final_result.length)

And also I already tried the answer from the question: What is the most efficient way to concatenate N arrays? and it did not work.

0 Answers0