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

132
Views
Filtering all objects apart from one and changing their values

I have an object which I want to filter only by shops:

const items = {
    "cars": {
        "porshe": {
            "active": true
        }
    },
    "shops": {
        "primark": {
            "active": true
        },
        "zara": {
            "active": true
        },
        "nike": {
            "active": true
        }
    }
}

 const filtered = Object.keys(items)
                .filter((key) => !['cars'].includes(key))
                .reduce((shops, key) => {
                    shops[key] = items[key];
                    return shops[key];
                }, {});
       
console.log(filtered);
                

Now I want to update all active values for "primark", "zara" and "nike" to active:false, and update my items object.

I have no idea how I can achieve that, I will be very grateful for every replies :)

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

0

Sometimes you only need simple for in loop for object updates which is faster.

for (let key in items.shops) {
  items.shops[key].active = false
}

Now you can check it with console.log(items);

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!