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
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 answers
Answer question

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