Reputation:
Below is the JSON i received from server.
Now i am having variable public checkId: any = 54
How to extract data corresponding to ID = 54
from below JSON ??
I want to extract below that is mentioned against KEY 54
"Increase Again": true,
"Decrease Previous" : true,
"Like" : true,
"Dislike" : true,
"Old Again" : false,
"Others" : true
Below is the JSON from which i have to extract above data
{
"27" : {
"Increase": true,
"Decrease" : true,
"Like" : true,
"Dislike" : true,
"Old" : false,
"Others" : true
},
"54" : {
"Increase Again": true,
"Decrease Previous" : true,
"Like" : true,
"Dislike" : true,
"Old Again" : false,
"Others" : true
},
"104" : {
"Increase Previous": true,
"Decrease Prior" : true,
"Like" : true,
"Dislike" : true,
"Old" : false,
"Others Check" : true
}
}
Thanks in advance ...
#Edit - The key are not simply 1,2,3 they are specific Id 53,54,55
also it can 100, 108, 4657
Upvotes: 1
Views: 324
Reputation: 578
You Can get Ur Desired Value simply like this..
let checkId = 2;
let data = {
"1": {
"Increase": true,
"Decrease": true,
"Like": true,
"Dislike": true,
"Old": false,
"Others": true
},
"2": {
"Increase Again": true,
"Decrease Previous": true,
"Like": true,
"Dislike": true,
"Old Again": false,
"Others": true
},
"3": {
"Increase Previous": true,
"Decrease Prior": true,
"Like": true,
"Dislike": true,
"Old": false,
"Others Check": true
}
}
let result = data[checkId]
console.log(result)
Upvotes: 1
Reputation: 108
You can simply get the specific element by passing the checkId in your response, For instance I'm assuming that you have that JSON in result variable.
You can call it in the following way
let result = //Your json;
let checkId = 2;
result[checkId] ==> This will return 2nd object of JSON
Upvotes: 1