Get Specific JSON Object by ID from array and return the JSON object (Javascript/JQuery)

I am trying to pull a specific JSON object from an array of objects using JavaScript. Here is my JSON:

"Awards": [    {      "Award1": {         "title": "Award1 Title",         "recipient": "John Doe",         "description": "Blah Blah Blah"      }    },    {      "Award2": {         "title": "Award2 Title",         "recipient": "Tom White",         "description": "Blah Blah Blah"      }    },    {       "Award3": {          "title": "Award3 Title",          "recipient": "Will Biggs",          "description": "Blah Blah Blah"       }    } ] 

What I want to be able to do is create a function that takes in the data and an id, finds the object in the array and returns the object as a whole. For example if I search for Award1, I want it to return:

var obj = {  "title": "Award1 Title",  "recipient": "John Doe",  "description": "Blah Blah Blah" } 

So then I could access the data like so:

obj.recipient // Which would return John Doe 

Ideas?

Professor Asked on October 26, 2020 in Android langue.
Add Comment
0 Answer(s)

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.