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 docs2y 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
Maxi1302y ago
Discord.js: └── discord.js@13.10.2 Node: v16.7.0
Jaworek
Jaworek2y ago
what is your problem?
Maxi130
Maxi1302y ago
I'm trying to convert a discord.js collection to json without losing the key names.
Jaworek
Jaworek2y ago
[...Collection.entires()]
d.js docs
d.js docs2y ago
method Collection#entries() Returns an iterable of key, value pairs for every entry in the map.
Maxi130
Maxi1302y ago
I will try, thank you!
Maxi130
Maxi1302y ago
How do I get something that can be saved into JSON out of this?
Jaworek
Jaworek2y ago
u didn't do like o said
Maxi130
Maxi1302y ago
Like this?
Maxi130
Maxi1302y ago
Or do what?
Jaworek
Jaworek2y ago
like that
Maxi130
Maxi1302y ago
Jaworek
Jaworek2y ago
what it consoles?