js sub string code example
Example 1: js substring
const str = 'Mozilla';
console.log(str.substring(1, 3));
console.log(str.substring(2));
Example 2: substring javascript
var str = "Hello world!";
var res = str.substring(1, 4);
Example 3: js substr
var str = 'abcdefghij';
console.log('(1, 2): ' + str.substr(1, 2));
console.log('(-3, 2): ' + str.substr(-3, 2));
console.log('(-3): ' + str.substr(-3));
console.log('(1): ' + str.substr(1));
console.log('(-20, 2): ' + str.substr(-20, 2));
console.log('(20, 2): ' + str.substr(20, 2));