jQuery(document).ready(function($) { $.getJSON("data.json", function(data) { function removeFromArray(array, item) { const index = array.indexOf(item); if (index > -1) array.splice(index, 1); return array; } var availableYears = []; var availableTags = []; selectedTags = ["Chat", "Fleur"]; selectedYears = ["2001", "2007"]; newData = data; function CheckTag(item) { for (tag of selectedTags) { if (!item.tags.includes(tag)) return false; } return true; } function CheckYear(item) { for (year of selectedYears) { if (item.year == year) return true; } return false; } newData = newData.filter(CheckTag); newData = newData.filter(CheckYear); console.log(newData); /*for (dat of data) { for (tag of selectedTags) { if (dat.tags.includes(tag)) { if (!availableYears.includes(dat.year)) availableYears.push(dat.year); else { console.log("remove year", dat.year); } splitTags = dat.tags.split(", "); for (splitTag of splitTags) { if (!availableTags.includes(splitTag)) availableTags.push(splitTag); } } } }*/ console.log("availableYears", availableYears); console.log("availableTags", availableTags); }); });