最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

JavaScript的:采取从String数组第一指定参数和让其余的再次加入

运维笔记admin26浏览0评论

JavaScript的:采取从String数组第一指定参数和让其余的再次加入

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();
发布评论

评论列表(0)

  1. 暂无评论