There is a socket server on JS. Users are connected to it. Now they are in an array. Some users have keys to other users with whom they correspond, in short chat. I thought it was an ideal option until I realized that users need to be deleted. And when deleting keys are shifted, or an empty cell is created. How can another implement. Maybe object somehow? Thank you in advance :)

    1 answer 1

    Object. Something like this:

    Users = { *userId*: { name: *name*, chats: { *chatId*: [*userId*, *userId*, ...], *chatId*: [*userId*, *userId*, ...], ... } }, ... } 

    Delete users and chats can be respectively:

     delete Users[userId]; delete Users.chats[chatId]; 
    • And how to specify links to objects, and delete them? - Accami September
    • Well, you create unique identifiers for users, here you have the keys. Removing from an object is also simply done - Vasily Barbashev