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

135
Vistas
How to find all arrays and not just the first occurance using find method in java script?

Here is my code:

const string = `1
00:01:46,356 --> 00:01:49,893
test test test test

2
00:01:50,794 --> 00:01:54,998
test test test red test test

3
00:01:55,199 --> 00:01:58,267
test test red`;

const match = st.split('\n\n').find((e) => e.includes('red'));


console.log(match);

the problem is it returns only the first occurance (the word "red" in 2nd sentence) while there is another "red" in the last sentence. What should I do to get all occurrences?

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Using find:

returns the value of the first element in the provided array that satisfies the provided testing function

Instead of find, you can use filter:

const match = string.split('\n\n').filter((e) => e.includes('red'));

const string = `1
00:01:46,356 --> 00:01:49,893
test test test test

2
00:01:50,794 --> 00:01:54,998
test test test red test test

3
00:01:55,199 --> 00:01:58,267
test test red`;

const match = string.split('\n\n').filter((e) => e.includes('red'));
console.log(match);

about 4 years ago · Juan Pablo Isaza Denunciar

0

Just use filter instead of find.

const st = `1
00:01:46,356 --> 00:01:49,893
test test test test

2
00:01:50,794 --> 00:01:54,998
test test test red test test

3
00:01:55,199 --> 00:01:58,267
test test red`;

const match = st.split('\n\n').filter((e) => e.includes('red'));


console.log(match);

about 4 years ago · Juan Pablo Isaza Denunciar
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