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

176
Views
How to check if all object with specific field name are true?

I have a problem with creating code. First, here is a categories array with field property. The second array is an element of categories with a property field (this property is the same as in category so I can recognize which element suits to category). How I can add property "edit" and "browse" to "categories" basing on elements of categories? It's something like a global checkbox if all of the elements with a category for example "tags" have edit or browse true/false then add a property to this category.

const categories = [
{
 name: "Tags",
 field: "tags",
//Here and in every object I want to add property edit: true/false, browse: true/false if all categoriesElements with field "tags" or other are true.
 hideFinance: false
},
{
 name: "Pixels",
 field: "retargeting_pixels",
 hideFinance: false
},
{
 name: "Dashboard",
 field: "dashboard",
 hideFinance: false
}
];

const categoriesElements = [
 {
   name: "Tags finance",
   field: "tags",
   edit: true,
   browse true
 },
 {
   name: "Tags channels",
   field: "tags",
   edit: true,
   browse true
 },
 {
   name: "Pixel creators",
   field: "pixel",
   edit: true,
   browse true
 }
]


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

0

You can use map and filter to achieve this. Below is the example of how you use the map an array based on other array.

const categories = [
{
 name: "Tags",
 field: "tags",
 hideFinance: false
},
{
 name: "Pixels",
 field: "retargeting_pixels",
 hideFinance: false
},
{
 name: "Dashboard",
 field: "dashboard",
 hideFinance: false
}
];

const categoriesElements = [
 {
   name: "Tags finance",
   field: "tags",
   edit: true,
   browse: true
 },
 {
   name: "Tags channels",
   field: "tags",
   edit: true,
   browse: true
 },
 {
   name: "Pixel creators",
   field: "pixel",
   edit: true,
   browse: true
 }
]


categories.map(cat=> {
    const ce = categoriesElements.filter(el=> el.field == cat.field);
    cat.edit = ce.length > 0 ? ce.every(elm => elm.edit) : false;
    cat.browse = ce.length > 0 ? ce.every(elm => elm.browse) : false;
    return cat;
})
console.log('categories', categories)

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!