I am looping through elements in an array. If a value is not within a specific range I want to remove the element (that the value is associated with).
Here's what i have so far (see code below) - I am using the pop method to remove the element as it comes through but the last element in the array always gets removed and NOT the element/value within the if/then statement. I've tried the splice method as well but I can't get that to work. Any idea on how to do this?
var h = [
["29","Verbena St", "500", "2", "2,702"],
["36", "Quitman St", "400", "2", "1,700"],
["32", "Alan Dr", "500", "2", "2,408"],
["34", "Newton St", "300", "2", "1,954"],
["30", "Soth Pl", "400", "2", "1,509"]
];
var hs = [
["Verbena St"],
["Quitman St"],
["Alan Dr"],
["Newton St"],
["Soth Pl"]
];
function Location (){
for (var r = 0; r <= h.length; r++){
var p = h[r][0];
var address = h[r][1]; // Get address
if (p >= 21 && p <= 33 && address == hs[r]){
console.log(address);
}
else {
console.log(address + " - OVER 33");
h.pop(address);
console.log(address + " - REMOVED");
}
}
};
Location();