0

Invoke any index

I have code: var words = "/getlyrics Artist - Song title"; word = words.split(' '); var command = word[0]; var artist = word[1]; var song = word[3]+ ' ' + word[4]; Can i call index third until last index with simple command? Without manually ( word[3]+' ' + word[4] + word[5] ...)

4th Jul 2019, 1:27 PM
Marhaen
Marhaen - avatar
1 Respuesta
+ 1
Yes, with the ES6 rest operator: let [command, artist, _, ...song] = words.split(" "); song = song.join(" "); The _ is used to skip one word, and ...song makes an array of the rest of the words. You can then join the again with the join method If you are not using this in a function (which I doubt), you might want to delete the _ variable
4th Jul 2019, 1:44 PM
Airree
Airree - avatar