I have a nested array that looks like this:
var nested_array = [
["18081163__,0,0.15,15238", "0", "0.15", "Somerset", "Local", "Norfolk Road"],
["18081165__,0.7,0.25,15239", "0", "0.15", "Somerset", "State", "Norfolk Road"],
["18081153__,0.1,0.25,15240", "0.1", "0.25", "Cumberland", "Local", "Potter Terrace"],
["18081164__,1.1,2.25,15241", "1.1", "2.25", "Cumberland", "State", "Jones Street"]
]
In each subarray, index 3 = county, index 4 = road_type, and index 5 = road_name. In my application, the user must choose the road_name. I created a simple function that takes on value and returns an nested array with subarrays that contain that value:
function array_parser(old_array, key_word) {
let new_array = [];
for (let i = 0; i < old_array.length; i++) {
if (old_array[i].includes(key_word)) {
new_array.push(old_array[i]);
}
}
return new_array;
}
This works well for a single value, but I want the user to be able to also choose the county and road_type optionally. If they do, I want to be a filter and return an array based on a list/array of values:
key_words = ["Somerset", "Norfolk Road"]
or
key_words = ["Somerset", "Local", "Norfolk Road"]
How can this be achieved?