Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

196
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda