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

102
Views
Filtering an array by object properties

I have an array of several thousand objects with properties, something like this

var plants = [];
plants [0] = {name: "Abronia", foliagecolor: "Pink", reproduction: "seeds", price: 3, group: "hz1", lifeform: "Herbs", plantsize: 20, usable: "hz1", crownsize: 30};
plants [1] = {name: "Aster", foliagecolor: "Violet", reproduction: "seeds", price: 2, group: "hz2", lifeform: "Shrubs", plantsize: 22, usable: "hz2", crownsize: 20};
plants [2] = {name: "Basil", foliagecolor: "Green", reproduction: "seeds", price: 1, group: "hz3", lifeform: "Herbs", plantsize: 25, crownsize: 32};
plants [3] = {name: "Cornflower", foliagecolor: "Blue", reproduction: "stem", price: 13, group: "hz4", lifeform: "Herbs", plantsize: 15, crownsize: 27};

There are 15 filters with the "control" class, each of which is a property of an object. For example - one of them:

<div class = "filteritem">
<span> Life Form </span> <br>
<select id = "lifeform" class = "control" data-name = "lifeform">
<option> - not selected - </option>
<option> Trees </option>
<option> Shrubs </option>
<option> Herbs </option>
</select>
</div>

I am trying to set up filters but nothing works. Please help me in which direction to look:

var query = {};
    $(".control").change(function() {
        var meaning = $(this).attr("data-name");
        Object.defineProperty(query, meaning,  {value : $(this).val(), configurable: true}); 
        console.log(query);
        var result = plants.filter(function(item) {
            for (var key in query) {
                if (item[key] === undefined || item[key] != query[key])
                    return false;
            }
            return true;
        });
        console.log(result);
    });
about 4 years ago · Juan Pablo Isaza
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!