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

92
Visualizações
Compare two items of the same array in JavaScript

I'm using react for this code. For a time now I been searching for how to do this, I have a array of arrays, and I need to compare if the beginning of the array is equal to beginning of the other array, then get all the next values of both arrays e put them in arrays that will populated a other array.

const chartValues = () => {
    dataValues.forEach((item) => {
      dataValues.forEach((item2) => {
        if ((JSON.stringify(item.slice(0, group.length))===JSON.stringify(item2.slice(0, group.length)))) {
          item.slice(group.length,group.length+select.length+1).forEach((item4, i)=>{
            setArrayData([...arrayData, ['{' + item.slice(0, group.length) +','+ select[i-1] + '}', item[group.length +i-1], item2[group.length + i-1]]])
          })
        } 
      })
    })
  }

I think it only compares with itself, never get to compare with item2.

dataValues = [
   ['g1','g2',1,2],
   ['g1','g2',3,4],
]

group = ['G1','G2']

select = ['F1','F2']

The result that i get from that is

arrayData= 
[ [ '{g1,g2,F1}', 1,1 ] ];

I want

arrayData=
[ [ '{g1,g2,F1}', 1, 3] , ['{g1,g2,F2}', 2,4] ];
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