let testData = [{ id: "13167", photo_cd: "9946", src: "", price: "5990", hf_section: "1", sell_price: "6469", design_id: "1", genre_id: "1", color_id: "1" }, { id: "13166", photo_cd: "9945", src: "", price: "5990", hf_section: "1", sell_price: "6469", design_id: "3", genre_id: "1", color_id: "1" }, { id: "13165", photo_cd: "9944", src: "", price: "5990", hf_section: "1", sell_price: "6469", design_id: "1", genre_id: "1", color_id: "4" }, { id: "13164", photo_cd: "9943", src: "", price: "6990", hf_section: "1", sell_price: "7549", design_id: "2", genre_id: "3", color_id: "3" }];
let fields = ["photo_cd", "hf_section", "design_id", "genre_id", "color_id", "price"];
function filterDataItems(data, filterParams) {
return data.filter(item => {
return fields.every((fieldName, index) => {
return filterParams[index] == 0 || (item[fieldName] == filterParams[index]);
});
});
}
console.log('Test 1: ', filterDataItems(testData, ["9946", "1", "1", "1", "0", "5990"]));
console.log('Test 2: ', filterDataItems(testData, ["0", "0", "0", "0", "4", "0"]));
console.log('Test 3: ', filterDataItems(testData, ["0", "0", "0", "0", "0", "0"]));
console.log('Test 4: ', filterDataItems(testData, ["0", "0", "0", "0", "0", "0"]));