javascript - Delete JSON data in array -
i trying remove piece of data json array. example, have array;
var users = []; io.on('connection',function(socket){ socket.on('nickname', function(nick){ socket.nick = nick; users.push({ user:socket.nick, userid:socket.id, socket:socket }); });
i trying delete in users way;
socket.on('disconnect', function(){ delete users[{ user, userid, socket }]; }); });
how can that?
you may try using lodash methods achieve trying to: -
var _ = require('lodash'); socket.on('disconnect', function(){ _.pullallwith(users, [{ user:socket.nick, userid:socket.id, socket:socket }], _.isequal) }); });
see if works..
Comments
Post a Comment