Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

227
Views
¿Cómo podemos filtrar una lista y mostrar el resultado si alguna parte del texto de entrada coincide con la lista javascript?

Tengo datos que vendrían de API que estoy tratando de filtrar. Básicamente, lo que quiero hacer es tener texto de entrada y si alguna palabra de mi texto de entrada se encuentra en la fuente, quiero obtener el valor

 //example 1 the word jerry is found in the list so it will console.log jerry findText ='is there a jerry' const list = ['jerry', 'reading', 'good'] const results = list.filter(e => e === findText) console.log(results) // jerry //example 2. the word reading and everyone is found in the list so console.log reading and good. findText ='is reading for everyone' const list = ['jerry', 'reading', 'good', everyone] const results = list.filter(e => e === findText) console.log(results) // reading
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Puede usar includes aquí como:

1)

 const findText = 'is there a jerry'; const list = ['jerry', 'reading', 'good']; const results = list.filter((e) => findText.includes(e)); console.log(results); // jerry

2)

 // example 2. the word reading and everyone is found in the list so console.log reading and good. const findText = 'is reading for everyone'; const list = ['jerry', 'reading', 'good', 'everyone']; const results = list.filter((e) => findText.includes(e)); console.log(results);

También puede usar Establecer aquí como:

 const findText = 'is reading for everyone'; const list = ['jerry', 'reading', 'good', 'everyone']; const findTextSet = new Set(findText.split(' ')); const results = list.filter((word) => findTextSet.has(word)); console.log(results); // ['reading', 'everyone']

about 4 years ago · Juan Pablo Isaza Report

0

ECMAScript 6 introdujo String.prototype.includes :

 let findText ='is reading for everyone'; const list = ['jerry', 'reading', 'good', 'everyone']; const results = list.filter(e => findText.includes(e) ); console.log(results); // ['reading', 'everyone']

Sin embargo, incluye no es compatible con Internet Explorer. En entornos ECMAScript 5 o anteriores, utilice String.prototype.indexOf , que devuelve -1 cuando no se puede encontrar una subcadena:

 let findText ='is reading for everyone'; const list = ['jerry', 'reading', 'good', 'everyone']; const results = list.filter(e => findText.indexOf(e) !== -1 ); console.log(results); // ['reading', 'everyone']

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!