I have a server that has an array that clients can interact with
I can add and delete to it however when checking if it's empty my if statement doesn't detect it
the array:
const queue = [];
adding to it:
socket.on("send-message", (data) => {
console.log("ping");
console.log(`${data.name},${data.message}`);
queue.push(data.name);
io.in(data.room).emit("receive-message", { data1: data, queue: queue });
console.log(queue);
});
here is the if statement in the delete section:
socket.on("delete-item", (data) => {
console.log(queue);
if (queue == []) {
console.log("empty");
}
if (queue === []) {
console.log(queue, "queue is empty");
io.to(socket.id).emit("error", "Queue is empty");
} else {
queue.pop(0);
io.in(data.room).emit("receive-delete", queue);
}
});
Aucun commentaire:
Enregistrer un commentaire