Divide and conquer: First, get access to the array of districts:
var districts = yourArray[0][0].active_districts;
From your picture, I can see that we want to access index 0
of the topmost array, and index 0
of that array. (I don't know why, but that's clear from the picture in your question. It's odd to have an array and just always grab the first entry from it.)
Now, find the district you want:
var district;
districts.some(function(d) {
if (d.id === yourDistrictId) {
district = d;
return true; // Stops loop
}
return false;
};
Now, provided district
is not undefined
, the schools are on district.schools
.
(That uses Array#some
, which was added in ECMAScript5 and is on all modern browsers. It's not on IE8 and some other older browsers, but it can be "polyfilled." So if you need to support older browsers, look for a polyfill. Or use a for
loop.)