JavaScript的:采取从String数组第一指定参数和让其余的再次加入
我有一个字符串数组,在这里我只需要第一个参数。其余的需要再次成为一个字符串。举个例子,我使用discord.js,我在/跳动命令工作,所以usermention将参数1,其余的将是真正的原因。但是,如何可以在阵列“参数”创建不使用的第一个索引整个字符串?目前,我刚刚得到这个:
//The given arguments in the command get separated
var Arguments = message.content.split(" ");
//testing purpose, if the first index really is the mentioned user
message.channel.send("Username: " + Arguments[1]);
//joining the reasons together to a whole string
var reason = Arguments.join(/*This is the part where I don't know how to tell the array to ignore the first index*/);
回答如下:
尝试在一开始的数组赋值参数:
var args = message.content.split(" ");
然后加入他们之前,你可以删除从args
的第一个元素:
args.shift();
JavaScript的:采取从String数组第一指定参数和让其余的再次加入
我有一个字符串数组,在这里我只需要第一个参数。其余的需要再次成为一个字符串。举个例子,我使用discord.js,我在/跳动命令工作,所以usermention将参数1,其余的将是真正的原因。但是,如何可以在阵列“参数”创建不使用的第一个索引整个字符串?目前,我刚刚得到这个:
//The given arguments in the command get separated
var Arguments = message.content.split(" ");
//testing purpose, if the first index really is the mentioned user
message.channel.send("Username: " + Arguments[1]);
//joining the reasons together to a whole string
var reason = Arguments.join(/*This is the part where I don't know how to tell the array to ignore the first index*/);
回答如下:
尝试在一开始的数组赋值参数:
var args = message.content.split(" ");
然后加入他们之前,你可以删除从args
的第一个元素:
args.shift();