I am trying to filter out all records that don't contain values from the 5 arrays: ssn, spn, smft, ssl, svtv. The output is not correct because it only works in cases where the lists contain 1 element. The output array becomes empty when they contain multiple elements. I am trying to get records that don't contain one of the values from each list (OR). I think it doesn't work because it checks if each record doesn't contain all values in each list (AND). Any idea how to fix this?
jsonData
[{"sn": "234234234", "pn": "1014143", "mft": "hello world", "sl": "GG07", "vtv": "Yes"},{"sn": "324234234", "pn": "101423131143", "mft": "hello world 1", "sl": "GG08", "vtv": "Yes"}]
query
ssn: ['T234834U', 'T23423423'],
spn: ['1014114', '21412342'],
smft: ['Sbasdfa', 'asdfaser'],
ssl: ['BB03', 'SFD04'],
svtv: ['Yes']
Code
function getFiltered() {
var query = {
sn: ssn,
pn: spn,
mft: smft,
sl: ssl,
vtv: svtv
}
var filtered = find_in_object(jsonData, query)
}
function find_in_object(my_object, my_criteria) {
return my_object.filter(function(obj) {
return Object.keys(my_criteria).every(function(c) {
return JSON.stringify(obj[c]).indexOf(my_criteria[c]) === -1
})
})
}
everytry to usesome- developer.mozilla.org/en/docs/Web/JavaScript/Reference/…