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

286
Vistas
How can I get the item that matches the criteria using some() and includes()?

I have an array of strings. I want to check if any of those strings is present in one sentence, so I used some() and includes(), and got a boolean telling me if any of the strings are present. So far so good.

Now, I need to know which of those strings is the one included in the sentence.

Here's my code:

var fruits = [
"apple",
"pear",
"orange",
"banana",
"grapes",
];

var text = "I want to eat a banana";

if (fruits.some(v => text.includes(v))) {
console.log("One of the fruits is in the sentence!");
}

I would need to get the value of that 'v', but I can't find a way to do it. Any ideas??

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

0

You could use find if its just one occurrence or filter if you want multiples:

var fruits = [
"apple",
"pear",
"orange",
"banana",
"grapes",
];

var text = "I want to eat a banana and an orange";

var foundFind = fruits.find(fruit => text.includes(fruit))
console.log("foundFind", foundFind);


var foundFilter = fruits.filter(fruit => text.includes(fruit))
console.log("foundFilter", foundFilter);

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