Which sub-string Javascript method should I use for maximum compatibility?
I thought about using substr() with a negative start number to extract the
last character of a string. But on w3 Schools, it says that it's not
compatible with IE8:
To extract characters from the end of the string, use a negative start
number (This does not work in IE 8 and earlier).
I've also read that there are performance problems.
So I decided to use the method below, which works, but is it best
practice, best for compatibility and good for performance?
q = 'Hello there!'
console.log(q.substring(q.length - 1, q.length));
// logs '!'
No comments:
Post a Comment