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

203
Views
No se pueden leer las propiedades de undefined (leyendo 'coincidencias')

Estoy tratando de filtrar a través de una matriz de objetos (álbumes en mi caso), pero recibo este error y todo lo que intenté no funcionó.

Mi barra de búsqueda:

 <input type="search" placeholder={" "} onChange={e => onChangeHandler(e.target.value)} value={text}/>

Mi onChangeHandler

 const onChangeHandler =(text) => { let matches = [] if (text.length > 0){ matches = albums.filter(album => { const regex = new RegExp(`${text}`, "gi") return (album.artist.matches(regex)); }); } console.log('matches', matches) setSuggestions(matches) setText(text) }

Cuando lo intento, funciona y obtengo las coincidencias en la consola, pero solo si escribo todo correctamente y distingo entre mayúsculas y minúsculas. Ese no es el objetivo aunque.

 return (album.artist === text);
about 4 years ago · Santiago Gelvez
2 answers
Answer question

0

Puede usar el método include de cadenas para esto. Entonces, para tu ejemplo, algo como esto:

 matches = albums.filter(album => album.artist.toLowerCase().includes(text.toLowerCase()));

Si desea que la búsqueda distinga entre mayúsculas y minúsculas, debe eliminar los métodos toLowerCase.

about 4 years ago · Santiago Gelvez Report

0

Probablemente hay 2 problemas en su código. Primero, no parece encontrar el album.artist , así que asegúrese de que su objeto se vea correcto.

En segundo lugar, las matches() no son una función en una cadena y probablemente te referías a las match()

 let albums = [{ artist: "Me" }, { artist: "You" }] const onChangeHandler = (text) => { let matches = [] if (text.length > 0) { matches = albums.filter(album => { const regex = new RegExp(`${text}`, "gi") return (album.artist.match(regex)); // Here matches => match }); } console.log('matches', matches) //setSuggestions(matches) //setText(text) } onChangeHandler("mE") onChangeHandler("me") onChangeHandler("yo")

about 4 years ago · Santiago Gelvez 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!