I have the following code which should filter one dynamic array (up to 300 thousands elements) from all elements not contained in another constant array:
orders[] // is already filled with data
let materials = [] // create empty array
for (let scheme in schemes) { // loop constant object
materials.push(schemes[scheme].typeID) // take id and add it to materials array
}
materials = Array.from(new Set(materials)) // filter out duplicates
console.log(materials) // everything looks fine here, 83 unique ids
for (let order in orders) { // now loop the main array
if (!materials.includes(orders[order].type_id)) { // if order's containment id is not found in materials array
orders.splice(order,1) // remove it from array
order -= 1 // and one step back to compensate removed index (do I need it or is it processed normally even after .splice?)
}
}
// and send filtered orders into browser when certain url is requested
However not all unnecessaty records are filtered out, there are lots and lots of them whose id cannot be found in materials array.
What is my mistake and where is error?