Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

95
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda