I am trying to get the last element of an array after doing 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 to do [this.length - 1] to get the last element of the array, but it gives me undefined, I know that some of you can say that they create another variable to store the array, but it's interesting to see if we can keep things in short.
unknown
source share