3 回答
TA贡献1789条经验 获得超10个赞
只需使用slice获取所有剩余的单词,并将它们重新组合成一个字符串:
var string = MessageString;
var temp = string.split(" ");
var CommandOne = temp[0];
var CommandTwo = temp[1];
var CommandThree = temp.slice(2).join(" ");
TA贡献1725条经验 获得超7个赞
您可以尝试以下操作
var string = MessageString;
var temp = string.split(" ");
var CommandOne = temp.shift();
var CommandTwo = temp.shift();
var CommandThree = temp.join(" ");
TA贡献1827条经验 获得超4个赞
Robin Zigmond 先发制人。切片是要走的路。
const message = '/report Tim for abusing chat';
const words = message.split(' ');
const action = words[0];
const username = words[1];
const reason = words.slice(2).join(' ');
console.log('action:', action);
console.log('username:', username);
console.log('reason:', reason);
添加回答
举报