Need help with getting array.filter to work with async function

Appreciate any pointers on why the filter function does not work as intended when an async function is used for filtering.

I expect the console output to be:

false
true
true

[20, 30]

However, it is:

[10 ,20 ,30]

false
true
true

Thanks.

const array1 = [10, 20, 30]

const filterArray = async (a) => {
  return a > 10
}

const result = array1.filter(e => {
  return filterArray(e).then(res => {
    console.log(res)
    return res
  })
})

if (result.length === 2) console.log('2 elements')
else console.log(result)

The objective is to check for duplicate records in a MongoDB and return a new file object (filteredObj) that does not contain records already existed in the DB. Each record has a description key.

hasDuplicateDescription method returns a Promise that resolves to a true or false, true if there is no existing record.description in the DB, false otherwise. However, the returned filteredObj has the original fileObj content, without any filtering done.

  const filteredObj = fileObj.filter((record) => {
    return this.hasDuplicateDescription(record.description).then(
      (res) => {
        return res;
      }
    );
  });
  return filteredObj;

The solution below was the recommended solution for getting async function to work with array.filter in other posts but it does not work in this case as hasDuplicateDescription is an async function that requires each array element passed in by the array.filter method as its argument.

const results = await Promise.all(your_promises)
const filtered_results = results.filter(res => //do your filtering here)

Appreciate any advice on how to approach this problem.

Thank you!

What about something like the following assuming all of the this is inside an async function?

async someFunction(){
  const records = [];
  fileObj.forEach(({ description }) => {
    records.push(
      this.hasDuplicateDescription(description).then(res => res)
    );
  });
  const filteredObj = await.Promise.all(records);
  return filteredObj;
}