#Why discord.js using collections
11 messages · Page 1 of 1 (latest)
• 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.
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
is forEach function faster than changing collection to json and then loop on them?
or the same speed
Yes, faster. Because you skip the conversion step
Converting a Collection to an array
You only need to convert it to an array if you need the index of an entry:
• Iteration (looping) is possible with for...of over Collection#values or forEach
• You can transform a Collection to an array with Collection#map
• If you need indices, you can get the array using [...collection.values()]
ok ty