Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

163
Visualizações
Sorting an array / table in JavaScript with keywords

I have a simple list and I am trying to create a search filter for this, you enter a keyword and it goes through the function and re-sorts this data list to show only ones that apply to the keyword

list: [
  {name: "Apple"},
  {name: "Grape"}
]
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Try Array.prototype.filter()

var list = [
  {name: "Apple"},
  {name: "Grape"}
];
var filtered = list.filter(function(o){
  return o.name == "Apple";
});
about 4 years ago · Juan Pablo Isaza Relatório

0

ili is right, Array.prototype.filter() is the good way but it would be much better with a String.prototype.includes() too, because the current answer can only works if the person type exactly the good word. Here is an implementation more user-friendly :

list = [
  {name: "Apple"},
  {name: "Grape"}
]

input = "app"

filtered = list.filter(element => {
    if(element.name.toLowerCase().includes(input.toLowerCase())) {
        return element
    }
})

console.log(filtered)

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda