My array of Exclusions is structured as shown below:
Exclusions: [ID:"233242", Loc:"West", ID:"322234" , Loc:"South"]
Within my Object, I have a nested array of objects that resembles:
Schools : [ O: [ ID:"233242" ] , 1:[ ID:"233242"] , 2: [ID :"954944"] ]
I am looking to remove any matching array indices with the same ID as in the Exclusions array, but only for the first match. This means that the element at index 0 should be deleted, while the element at index 1 should remain. How should I adjust my loop for this:
$.each(Exclusions, function (index, value) {
var loc = value.Loc;
var ID = value.ID;
Object.keys(Schools.District.Pack[loc]).forEach(function (key) {
//need to iterate through the entire object
if (Schools.District.Pack[loc].ID === ID) {
//remove the first match and stop searching
Schools.District.Pack[loc].splice(key, 1);
//break; this is incorrect
}
});
});