3 回答

TA貢獻(xiàn)1789條經(jīng)驗(yàn) 獲得超10個(gè)贊
只需使用slice獲取所有剩余的單詞,并將它們重新組合成一個(gè)字符串:
var string = MessageString;
var temp = string.split(" ");
var CommandOne = temp[0];
var CommandTwo = temp[1];
var CommandThree = temp.slice(2).join(" ");

TA貢獻(xiàn)1725條經(jīng)驗(yàn) 獲得超8個(gè)贊
您可以嘗試以下操作
var string = MessageString;
var temp = string.split(" ");
var CommandOne = temp.shift();
var CommandTwo = temp.shift();
var CommandThree = temp.join(" ");

TA貢獻(xiàn)1827條經(jīng)驗(yàn) 獲得超4個(gè)贊
Robin Zigmond 先發(fā)制人。切片是要走的路。
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);
添加回答
舉報(bào)