Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

178
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda