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

177
Visualizações
fetch the json value and assign in json using node js / javascript

let arrayId={
  "za": {
    "gasjxhj6782": {
      "value": "gasjxhj6782",
      "access": "Available at some point"
    },
    "vghasj56728": {
      "value": "vghasj56728",
      "access": "Access denied"
    },
    "ldghjd67821": {
      "value": "ldghjd67821",
      "access": "Admin role"
    }
  },
  "cn": {
    "hjaks7812": {
      "value": "hjaks7812",
      "access": "Available at some point"
    },
    "78912ashm": {
      "value": "78912ashm",
      "access": "Access denied"
    }
  },
  "tw": {
    "78912ashm": {
      "value": "78912ashm",
      "access": "Access denied"
    }
  }
};

let obj="hjaks7812";

function blockAccess(obj) {
  if (obj in arrayId) {
    attrs = {
      "type": "Access permission",
      "entry-level-id": "",
      "key": "",
      "access": "",
    };
  }
  console.log(attrs);
}

This is my function I want to check the value of obj present in arrayId and assign the value

for eg obj is hjaks7812 I want to check it present at which level of arrayId

and make my expectation output as this if the value is hjaks7812

{
  "type": "Access permission",
  "entry-level-id": "hjaks7812",
  "key": "cn",
  "access": "Available at some point",
}

but value of obj get changed maybe it can be gasjxhj6782 or any thing then it should take that value if the obj value is like this gasjxhj6782 then expectation value will be like this

{
  "type": "Access permission",
  "entry-level-id": "gasjxhj6782",
  "key": "za",
  "access": "Available at some point",
}

as I want to check obj at which level and assign that value here za cn tw get changed everytime as this is user define so I want to check at which level the value which is assign in obj is present and fill that attr

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can try this approach with entries and double loop

let arrayId = {
  "za": {
    "gasjxhj6782": {
      "value": "gasjxhj6782",
      "access": "Available at some point"
    },
    "vghasj56728": {
      "value": "vghasj56728",
      "access": "Access denied"
    },
    "ldghjd67821": {
      "value": "ldghjd67821",
      "access": "Admin role"
    }
  },
  "cn": {
    "hjaks7812": {
      "value": "hjaks7812",
      "access": "Available at some point"
    },
    "78912ashm": {
      "value": "78912ashm",
      "access": "Access denied"
    }
  },
  "tw": {
    "78912ashm": {
      "value": "78912ashm",
      "access": "Access denied"
    }
  }
};

function blockAccess(key) {
  for (const [arrayKey, arrayValue] of Object.entries(arrayId)) {
    for (const [accessKey, accessValue] of Object.entries(arrayValue)) {
      if (accessKey === key) {
        return {
          "type": "Access permission",
          "entry-level-id": accessKey,
          "key": arrayKey,
          "access": accessValue.access,
        };
      }
    }
  }
  return 'Not found'
}

console.log(blockAccess("hjaks7812"))
console.log(blockAccess("gasjxhj6782"))
console.log(blockAccess("testing")) //Not found if the key is not in your data

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