Collection problem
Is there any easy way to modify an array that is placed as a value in an Collection object?
6 Replies
- What's your exact discord.js
npm list discord.js
and node node -v
version?
- Not a discord.js issue? Check out #other-js-ts.
- Consider reading #how-to-get-help to improve your question!
- Explain what exactly your issue is.
- Post the full error stack trace, not just the top part!
- Show your code!
- Issue solved? Press the button!
- ✅
Marked as resolved by staffIm thinking about doing this:
but in an easier way
You don't have to
set()
the key to the "new" value
Arrays are just pointers in JS, so if you modify an array in one place, it modifies the array elsewhere too since both the array you modified and the array currently in the collection both point to the exact same memory address
Other than that, you're doing it in the easiest way possible
You could combine all of it into one line collection.get("xyz").push("4")
but that isn't really changing anything under the hoodthank you!
One more question, would
collection.get("xyz")["array"].push("4")
work too?Looks like it
Tysm