Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

190
Views
Number of arrays generated by JavaScript function is one less than expected

I have a dataset of various arrays and objects which is irrelevant to be presented here. The following spr function uses the data to return a multidimensional array defined as arry with the length of six:

function spr() {
  let ctgnum = 1;
  let selectionOfCtg = [];
  // debugger;
  for (let i = 0; i < ctg_assoc[ctgnum].length; i++) {
    value =
      ctg_assoc[ctgnum][i][
        Math.floor(Math.random() * Object.values(ctg_assoc[ctgnum][i]).length)
      ];
    selectionOfCtg.push(value);
  }

  console.log(selectionOfCtg);
  let arr = [];
  let arry = [];
  for (let e of selectionOfCtg) {
    len = Object.keys(ctg_ptr[e]).length;
    for (let f = 0; f < len; f++) {
      arr.push(Object.keys(ctg_ptr[e][f]));
    }
    arry.push(arr.flat());
    arr = [];
  }
  return arry;
}

arry = spr();
console.log(arry);

When the function is run by itself console.log(arry); returns six arrays as expected and required. However, when the following piece of code is added after the function to find common values within the six arrays, the the first array becomes omitted, hence returning only five arrays:

let result = arry.shift().filter(function (v) {
  return arry.every(function (a) {
    return a.indexOf(v) !== -1;
  });
});

Any idea what might be causing it?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!