I have a group of checkboxes on a page that, when clicked, create an array of values (allVals) that change as boxes are checked/unchecked (string output is also an option). I also have another multidimensional array (recordSet), which I would like to filter (in example below: recordSet[i][5]) based on the checked values (allVals), and then return a new multidimensional array with only the matching indexes and their values. In this case it would return only the first recordSet[0] because "cat" was included. Each time a check box is checked/unchecked, recordSet would be filtered again and the newly created multidimensional array would update.
I have looked into underscore.js, which I am also using on the page, but unsure as to how to construct the filter and loops. Any help is much appreciated to point me in the right direction - open for other suggestions to accomplish.
allVals = ["cat", "dog"]
recordSet = 0: Array[6]
0: "somevalue"
1: "somevalue"
2: "somevalue"
3: "somevalue"
4: "somevalue"
5: "Cat;Monkey;Elephant;Rooster"
length: 6
1: Array[6]
0: "somevalue"
1: "somevalue"
2: "somevalue"
3: "somevalue"
4: "somevalue"
5: "Giraffe;Turtle;Rabbit;Snake"
length: 6
function updateSubTopics() {
var allVals = [];
$('.subCheck').each(function() {
if (this.checked){
allVals.push($(this).val());
}
});
$(function() {
$('.subCheck').click(updateSubTopics);
updateSubTopics();
});