javascript:从字符串数组中获取第一个参数,然后让其余的再次加入

标签 javascript node.js

我有一个字符串数组,我只需要第一个参数。其余的需要再次成为一个字符串。例如,我使用 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/

相关文章:

javascript - 如何关闭该选项卡? (Octobercms 组件,Javascript)

javascript - 更改联系表中的验证要求

Node 服务器中的javascript语法错误

javascript - log4js https 日志记录端点

node.js - 在 Mongoose 中按月分组

javascript - AngularJS watch - 无法使用 devtools 工作区在 chrome 中设置断点

javascript - 页面/表格加载动画

javascript - 尝试定义数组

json - sequelize.query() 两次返回相同的结果

node.js - NodeJS Express 站点