var str = "I learn JavaScript";
alert( str.slice(8) ); // returns 'JavaScript'
Note: the Array slice() method uses its arguments to copy another array from element X to Y.
var str = "I learn JavaScript";
alert( str.slice(8, 12) ); // returns 'Java'
var str = "I learn JavaScript";
alert( str.slice(-1) ); // returns 't'
var str = "I learn JavaScript";
alert( str.slice(-5, 5) );
$str = 'I learn PHP';
echo substr( $str, -3, 3 ); // returns 'PHP'
echo substr( $str, -3 ); // also returns 'PHP'
Sister method: substring() takes a positive start and end index to return a smaller string.