substr in node js code example
Example 1: js substring
const str = 'Mozilla';
console.log(str.substring(1, 3));
console.log(str.substring(2));
Example 2: js get first 3 characters of string
const string = "0123456789";
console.log(string.slice(0, 2));
console.log(string.slice(0, 8));
console.log(string.slice(3, 7));
Example 3: substr() javascript
const str = 'substr';
console.log(str.substr(1, 2));
console.log(str.substr(1));
console.log(str.substr(-3, 2));
console.log(str.substr(-3));
Example 4: 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));