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

96
Visualizações
Compare select parts of 2 Strings
0: {Id: 1, type: dog, changeNo: '0123-123-A1', …}
1: {Id: 2, type: cat, changeNo: '0123-123-F2', …}
2: {Id: 3, type: bus, changeNo: '0456-154-E5', …}
n: {Id: n, type: n, changeNo: 'n', …}
length: n

So I'm currently learning JS and react and am trying to check an object array in the form above for the same changeNo up to the second '-'. So I'd like to know if, and how many '0123-123' there are. I figured I'd iterate over the array checking for whether either string is a subset of the other, however that would lead me into errors with almost everything as it checks the adjacent Lettering as well.

let multi: number;
    for (let i=0; i <= data.length; i++) {
        for (let j=1; j <= data.length; j++) {
            while (data[i].changeNo.indexOf(data[j].changeNo) >-1) {
                multi ++;
            }
        }
    } 
return multi-1;

Is there a way to easily compare the strings in a for while loop based on the first few elements. Or maybe a way to stop comparing once the second '-' is reached?

Thanks in advance!

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