const str = 'substr';
console.log(str.substr(1, 2)); // (1, 2): ub
console.log(str.substr(1)); // (1): ubstr
/* Percorrendo de trás para frente */
console.log(str.substr(-3, 2)); // (-3, 2): st
console.log(str.substr(-3)); // (-3): str
//str.substr(start[, length])
var str = 'abcdefghij';
console.log('(1, 2): ' + str.substr(1, 2)); // '(1, 2): bc'
console.log('(-3, 2): ' + str.substr(-3, 2)); // '(-3, 2): hi'
console.log('(-3): ' + str.substr(-3)); // '(-3): hij'
console.log('(1): ' + str.substr(1)); // '(1): bcdefghij'
console.log('(-20, 2): ' + str.substr(-20, 2)); // '(-20, 2): ab'
console.log('(20, 2): ' + str.substr(20, 2)); // '(20, 2): '
const str = "Learning to code";
// start index is 1, length is 4
console.log(str.substr(1, 10));
// start index is 3, length is 2
console.log(str.substr(3, 2));
// length not given
// string extract to end of the string
console.log(str.substr(5));
//substr() is similar to slice().
//The difference is that the second parameter specifies the length of the extracted part
let str = "Apple, Banana, Kiwi";
let part = str.substr(7, 6);
// >> Banana
//if you find this answer is useful ,
//upvote ⇑⇑ , so can the others benefit also . @mohammad alshraideh ( ͡~ ͜ʖ ͡°)
var string = "WelcomeToSofthunt.netTutorialWebsite";
one = string.substr(0, 7)
two = string.substr(7, 2)
three = string.substr(9,12)
four = string.substr(21, 8)
five = string.substr(29,36)
six = string.substr(0)
document.write(one);
document.write(two);
document.write(three);
document.write(four);
document.write(five);
document.write(six);
string.substr(startIndex[, length])