-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest2.js
32 lines (28 loc) · 891 Bytes
/
test2.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
const jsonData = require('./eventData');
function filterObjectsByProperties(jsonArray, filterCriteria) {
return jsonArray.filter(obj => {
for (const property in filterCriteria) {
if (property === "params" && typeof filterCriteria[property] === "object") {
const params = filterCriteria[property];
for (const paramKey in params) {
if (obj[property] && obj[property][paramKey] !== params[paramKey]) {
return false;
}
}
} else if (obj[property] !== filterCriteria[property]) {
return false;
}
}
return true;
});
}
const filterCriteria = {
deviceId: 'fb5070b3-22c9-4634-f871-8f0fac267975',
"params": {
"duration": 0.0,
}
};
const filteredData = filterObjectsByProperties(jsonData, filterCriteria);
// Log the filtered data
console.log(filteredData);
console.log(filteredData.length);