I am currently working on a function that loops through elements in an array and removes values outside of a specific range. However, I have encountered an issue where using the pop method always removes the last element in the array rather than the intended value within the if/then statement.
Below is the code snippet I am using. I have also attempted to use the splice method without success. Any suggestions on how to fix this problem would be greatly appreciated!
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();