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

183
Visualizações
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 Respostas
Responde à pergunta

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