Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do i search by ID in json file?

so let’s say i have this JSON file:

{
  "1": {
    "name": "some random name 1",
    "nickname": "some random nickname 1"
  },
  "2": {
    "name": "some random name 2",
    "nickname": "some random nickname 2"
  }
}

And i need function that searches by ID,("1": / "2": is ID basically) and saves it in variable. (Using Javascript). I just don’t know how to do it.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Why not just standard bracket notation for this…?

var object = {
  "1": {
    "name": "some random name 1",
    "nickname": "some random nickname 1"
  },
  "2": {
    "name": "some random name 2",
    "nickname": "some random nickname 2"
  }
}

console.log(object["1"]);
console.log(object["2"]);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading