我有一个字符串数组,我只需要第一个参数。其余的需要再次成为一个字符串。例如,我使用 discord.js,并且我使用/kick 命令,所以 usermention 将是参数 1,其余的将是原因。但是数组“Arguments”如何在不使用第一个索引的情况下创建一个完整的字符串呢?目前我刚得到这个:
//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:从字符串数组中获取第一个参数,然后让其余的再次加入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54531899/