Search code examples
javascriptarraysdiscord.jsline-breaks

How can I get the elements of an array without the brackets and no line break?


What I want:

var word = ["happy", "penguin", "sword"]

message.channel.send(word)

//prints 
"happy", "penguin", "sword"

What actually happens:

var word = ["happy", "penguin", "sword"]

message.channel.send(word)
//prints
happy
penguin
sword

This is on discord.js, Thanks.


Solution

  • Join the array into a string, and then send that instead.

    const word = ["happy", "penguin", "sword"];
    
    const str = `"${word.join('", "')}"`;
    
    console.log(str);

    Additional documentation