I have my json like this. I need to get the data whose index is 101. Is there smarter way to query that.
[{
"Name": "Ana",
"Class": 3,
"index": 0,
"Subject": [
{
"Sub1": "Maths",
"Sub2": "Science",
"index": 00,
"Speciality": [
{
"Spcl": "Music",
"Spcl2": "Sports",
"Spcl3": "Singing",
"index": "000"
}
]
}
]
},
{
"Name": "Ben",
"Class": 3,
"index": 1,
"Subject": [
{
"Sub1": "Maths",
"Sub2": "Science",
"index": 10,
"Speciality": [
{
"Spcl": "Music",
"Spcl2": "Sports",
"Spcl3": "Singing",
index: 100
},{
"Spcl": "Music",
"Spcl2": "Sports",
"Spcl3": "Singing",
"index": "101"
}
]
}
]
},
{
"Name": "David",
"Class": 3,
"index": 2,
"Subject": [
{
"Sub1": "Maths",
"Sub2": "Science",
"index": 20,
"Speciality": [
{
"Spcl": "Music",
"Spcl2": "Sports",
"Spcl3": "Singing",
"index": "200"
}
]
}
]
}]
Here is what I am trying.
accessData(myData,index) {
// my index in 101 for example
for(var i=0; i<index.length; i++){
if(index.length == 3){
my result = myData[i].subject[i+1].Speciality[i+2]
}if(index.length == 3){
my result = myData[i].subject[i+1]
}else{
my result = myData[i];
}
}
)
}
But here my subject and specity may changes in some time so I want to query at index level and do my operation. Is there any way to get that.