Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Removing more then one item from an array after clicking twice using socket.io

app.js
queueing = [];

//Add to queue socket.on('add queue', function(data) { queueing.push(data); console.log(queueing); delete data; //Remove From queue socket.on('remove queue', function(data) { console.log(queueing.indexOf(data)); queueing.splice(queueing.indexOf(data), 1); console.log(queueing); delete data; });

index.ejs

$queueStart.click(function(){
            <% if (user) { %>
            var $id = <%=user.id%>;
            console.log($id);
            <% } %>
            socket.emit('add queue', $id);
            delete $id;
        });
        $queueStop.click(function(){
            <% if (user) { %>
            var $id = <%=user.id%>;
            console.log($id);
            <% } %>
            socket.emit('remove queue', $id);
            delete $id;
        });

after trying to add to the queue twice with the same user it sets the index of the id to -1 (tested with only two users)

any idea why thats hapenning and how to fix it?