Home > Net >  How do I return an array without the "," separator?
How do I return an array without the "," separator?

Time:01-02

I'm doing this for a bot to get arguments but I do not know how to remove the "," in the arrays.

args = ['A', 'spaced', 'argument']
nick = "someone"
client.send(args   ' was killed by '   nick   ' successfully.')

returns

A,spaced,argument was killed by someone successfully.

in the server I used to connect "client" to. How do I remove the "," separator?

CodePudding user response:

When you concatenate an array with a string, javascript by default prints out each array element separated by a comma. You can instead join the strings in the array to form one string:

client.send(args.join(" ")   ' was killed by '   nick   ' successfully.')

CodePudding user response:

yo can use join("seprator") to get what you want ex:

const fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.join(" and ");

result : Banana and Orange and Apple and Mango

CodePudding user response:

You can use the join() method, it returns a new string by concatenating all of the elements in an array.

args = ['A', 'spaced', 'argument']
nick = "someone"
client.send(args.join(" ")   ' was killed by '   nick   ' successfully.')
  • Related