Skip to content
Advertisement

how do i filter a data in quickmongoi so that it would show only names of users who are in the guild only in the leaderboard command

js and quickmongo for a leaderboard command but it shows the named of all the users in the database and I want it to show names of users who are in the guild only. Any help is highly appreciated 🙏. I tried filtering it too… My current code

JavaScript

Help me please

Advertisement

Answer

Array#filter() doesn’t modify arrays in place, it only returns the filtered result. For example:

JavaScript

So, you’ll simply need to reassign data to the filtered array.

JavaScript

However, this still won’t work. This is because you’re filtering the array within a callback. The whole purpose of a callback is to trigger after a promise is resolved, so by the time you’re able to filter the array, all of the other code will have already been executed.

Understanding promises:

If you choose to use async/await, you can refactor your code like so:

JavaScript

While working, this solution is not optimal, since you have to filter and reassign data for every single member. Instead, you should try to only do it once. You can achieve this using Array#some()

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement