Convert discord.js collection to json with keeping keys and values

I already tried Collection.toJSON() but it removes the key name and converts it into an array. Code:
console.log(Collection)
console.log(Collection.toJSON())
console.log(Collection)
console.log(Collection.toJSON())
Output:
Collection(1) [Map] { 1 => '506039613731897344' }
[ '506039613731897344' ]
Collection(1) [Map] { 1 => '506039613731897344' }
[ '506039613731897344' ]
14 Replies
d.js docs
d.js docs3y ago
• 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.
Maxi130
Maxi130OP3y ago
Discord.js: └── [email protected] Node: v16.7.0
Jaworek
Jaworek3y ago
what is your problem?
Maxi130
Maxi130OP3y ago
I'm trying to convert a discord.js collection to json without losing the key names.
Jaworek
Jaworek3y ago
[...Collection.entires()]
d.js docs
d.js docs3y ago
method Collection#entries() Returns an iterable of key, value pairs for every entry in the map.
Maxi130
Maxi130OP3y ago
I will try, thank you!
Maxi130
Maxi130OP3y ago
How do I get something that can be saved into JSON out of this?
Jaworek
Jaworek3y ago
u didn't do like o said
Maxi130
Maxi130OP3y ago
Like this?
Maxi130
Maxi130OP3y ago
Or do what?
Jaworek
Jaworek3y ago
like that
Maxi130
Maxi130OP3y ago
Jaworek
Jaworek3y ago
what it consoles?
Want results from more Discord servers?
Add your server