0

Possible Duplicate:
array join() method without a separator

I'm trying to code a simple array that will then be displayed as a single, continuous line of text with no comma's gaps or separations of any kind. For example, if the array was about fruit, and the fruit involved were apples[0] and bananas[1], it would be displayed as applesbananas.

I am also using socket io and tried the array.join command, but that came up as a 'native expression' in the cmd, which I wasn't sure what to do with.

This is the code I have so far:

var A = 0
var B = 0
var master = new Array();

io.sockets.on("connection", function (socket) {


    socket.on("message", function (data) {

        var new_data = data.split(',');

        if (new_data == 'A') {
            master.push(new_data)
            console.log(A);
        }
        else if (new_data == 'B') {
            master.push(new_data)
            console.log(B);
        }
        var final = (master.join);
            console.log(final);
            socket.emit("message", 'master,' + final);
            socket.broadcast.emit("message", 'master,' + final);

Right now, this .join expression is being displayed as a native expression in the cmd. Is there any way to join the array elements in a way the cmd or socket io will understand?

Thanks for the help!

2

2 Answers 2

2

You're seeing that error because you're missing parenthesis after your call to .join.

You can join an array with no spaces using .join('').

Sign up to request clarification or add additional context in comments.

Comments

1

Try this:

var final = master.join("");

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.