#Why discord.js using collections

11 messages · Page 1 of 1 (latest)

silent belfry
#

I really don't understand why discord.js using collections for everything instead of arrays

Is it better for performance? or it's just a convenient way for new developers?

latent stormBOT
#

• What's your exact discord.js npm list discord.js and node node -v version?
• Post the full error stack trace, not just the top part!
• Show your code!
• Explain what exactly your issue is.
• Not a discord.js issue? Check out #useful-servers.

dreamy fossil
#

It provides a mapping of ids to instances. Instead of an array where you need to search for the right element sequentially. So yes, Performance when looking up a specific element is better

#

Also collections provide additional methods you don’t have on arrays

silent belfry
#

is forEach function faster than changing collection to json and then loop on them?

#

or the same speed

dreamy fossil
#

Yes, faster. Because you skip the conversion step

latent stormBOT
silent belfry
#

ok ty

red trellis
#

it's worth actually mentioning what Collections are

#

Collection extends native Map by adding Array methods