Skip to content

Tag: node.js

How can I sort this array in Discord.js?

I have an array, that looks like this(size changes): The first value is the member id, the second how many messages the user has. How can I sort the array, to get the first 10 members, sorted by their messages send? The code: Answer To sort an array by numbers, you can use the .sort() method with a compare fu…

session value is not stored properly

I am using express-session and express-mysql-session in my app to generate sessions and store them in mysql database. Sessions are stored in a table called sessions. Sessions are stored in table but the value of it is not as same as the session value in client-side or console. Example: decoded value in client…

Create new object if it doesn’t exist, else update

I’m having quite some trouble handling objects and storing them as JSON. What I’m trying to do is next: parse json file If user1 exists, update the whole object with new data, ELSE create new object As you can probably tell, the above doesn’t work as I’d want it to. I’m used with…