Please advise if the following code is the best way to remove an object from an array while performing async functions:
// arr1 holds objects that I've already pulled from the remote db in the past
const arr1 = [ { "hi": "there", "bye": "now" }, ... ]
const conn = connectToRemoteDB()
// loop through list of type of things that I want to pull from remote db
for (const x in listOfObjects)
{
// this is async
conn.execute(sql)
.then (result =>
{
let exists = false
// loop on arr1. can be thousands of objects
for (const i in arr1)
if (result.id === arr1[i].id)
{
exists = true
arr1.splice(i, 1)
break
}
}
}
// will this always be accurate so
// I know anything left in arr1 has been removed from the remote DB