I have the following code that works fine. However I don’t know how I can add additional conditions to the filter, i.e in this code although it works fine I only want it to return venues that have an active value==1; (so in this case the venue with the SKU 1007 is not returned).
In the example I have commented out a for loop that achieves the result I want but I want to use filter instead.
Many thanks.
Can anyone help with this.
<script>
db = {};
db.venueDB = [
{
SKU : 1001,
active : 1,
round : 1,
date : "02/03/2026",
country : "Germany",
},
{
SKU : 1002,
active : 1,
round : 2,
date : "23/04/2026",
country : "Czechia"
},{
SKU : 1003,
round : 3,
active : 2,
date : "05/05/2026",
country : "United Kingdom"
},{
SKU : 1004,
round : 5,
active : 1,
country : "Spain",
date : "20/07/2026"
},{
SKU : 1005,
round : 6,
active : 1,
country : "Sweden",
date : "21/07/2026"
},{
SKU : 1006,
active : 1,
round : 7,
country : "Brazil",
date : "01/98/2026"
},{
SKU : 1007,
active : 4,
round : 8,
country : "Latvia",
date : "08/09/2026"
},{
SKU : 1008,
round : 9,
active : 1,
country : "Denmark",
date : "12/10/2026"
}
];
db.SKU = [1002,1005,1001,1008,1007,1001,1004];
const venueBySku = db.venueDB.values().map((venue) => [venue.SKU, venue]);
const lookup = new Map(venueBySku);
const result = db.SKU.filter(sku => lookup.has(sku)).map(sku => lookup.get(sku));
for(n=0; n<result.length; n++){
//if(result[n].active==1){
document.write(n+"] "+result[n].SKU+" "+result[n].active+" "+result[n].country+"<br/>");
//};
};
</script>