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

150
Views
Filtrar si la matriz de cadenas coincide parcialmente

Quiero filtrar la matriz si contiene una cadena en particular. Funciona como se muestra a continuación. Pero no estoy seguro de cómo resolverlo si hay varias cadenas para hacer coincidir. Por ejemplo, en lugar de skillText = "Entry Level"; si tenemos skillText = ["Entry Level", "Scientist", "Analyst"];

 var myList = [{"Title":"Entry Level - Data Analyst","Location":"Boston"}, {"Title":"Entry Level3 - Analyst","Location":"Delhi"}, {"Title":"Scientist","Location":"Boston"}]; skillText = "Entry Level"; result = myList.filter(function(v) { return v["Title"].indexOf(skillText) > -1; }) console.log(result);

Para la coincidencia exacta, skillText.includes(v["Title"]) funciona, pero no estoy seguro de cómo hacerlo con las coincidencias parciales.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Puede usar some función en matrices, devuelve verdadero si alguno de los elementos devuelve verdadero desde la devolución de llamada

 skillTexts = ["Entry Level", "Scientist"]; result = myList.filter(function(v) { return skillTexts.some(function(skill) { return v["Title"].includes(skill) }); })
about 4 years ago · Juan Pablo Isaza Report

0

Esta puede ser una posible solución para lograr el objetivo deseado:

Fragmento de código

 const findMatches = (hayStack, needle) => ( hayStack.filter( ({Title}) => ( [].concat( needle ).some( skill => Title.includes(skill) ) ) ) ); const myList = [{"Title":"Entry Level - Data Analyst","Location":"Boston"}, {"Title":"Entry Level3 - Analyst","Location":"Delhi"}, {"Title":"Scientist","Location":"Boston"}]; let skillText = 'Entry Level'; console.log('searching text: "Entry Level"\nfound: ', findMatches(myList, skillText)); skillText = ['Level', 'Analyst', 'Scientist']; console.log('searching array', skillText.join(), '\nfound: ', findMatches(myList, skillText));

Explicación

  • Use .filter para iterar sobre la matriz ( hayStack )
  • Desestructurar para acceder directamente al Title desde el iterador
  • Para acomodar needle (el texto de búsqueda es una cadena o una matriz), primero use [].concat() para obtener una matriz (Esto se hace según el comentario de pilchard en la pregunta anterior)
  • Use .some para iterar y encontrar si algún elemento es parte del Título
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!