This site is mobile accessible. Press the "Tap Here" button to use a smaller font-size.

Smartphone icons created by Freepik - Flaticon

JavaScript String Methods

The substr() method extract a part of a string and returns the extracted parts in a new string:

let str = "Apple, Banana, Kiwi";
document.getElementById("demo").innerHTML = str.substr(-4);

Because the substr starts at a specified spot in the string and goes to the end of the specified length (substr(start, length)) it always goes from left to right. If a length is not specified, the selection is to the end of the string.