I’m trying to get the last array item after doing a split on a string using javascript.
var str ="Watch-The-Crap-456".split('-')[this.length];
console.log(str);
// want it to console log 456, now it consoles WATCH which is in array[0]
I tried doing [this.length - 1] to get me the last array item, but it gives me undefined, I know some of you might say create another variable to store the array, but it’s interesting to see if we can keeps things shorter.
How about: