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

161
Views
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 answers
Answer question

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 Report

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 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!