What is the better way to remove the "parent index of" of an array?

enter code hereIm making an nodejs application... let me show my question;;

//id = dinamic string.. "user1", "user2", "userX"  
usersArray = [];
usersArray[id]["socket"] = socket;

When sockets ends, I want to remove [id] from usersArray.. but at this time id is not availabe

socket.on('end', function () {
    ?........?
    socket.end();
});

How to do it?

There's socket.id which works well as an identifier for each socket. Then, you can use an associative array instead of usersArray:

var usersArray = {};
usersArray[socket.id] = some_user_data;

You can then remove this entry using delete usersArray[socket.id].

Assuming you have access to thisId from inside the socket.on('end') function, you could do something like:

socket.on('end', function () {
    usersArray.splice(thisId, 1);
    socket.end();
});

Depending on where you add the sockets to your userArray (which seems to be an object rather than an array noticing your examples for id), you could consider just adding a new callback to the socket when you add it to the array

usersArray[someId].socket = socket;

// New callback to just delete the usersArray entry
usersArray[someId].socket.on('end', function() {
   delete usersArray[someId];
});

Leave the current socket.on untouched:

socket.on('end', function () {
    /* No new code here, as the deletion happens
       when the socket is added to usersArray!
     */
    socket.end();
});