1var str = "Hello world That is reallly neat!";
2var res = str.substring(0, 5);//get first 5 chars
1// the substring method returns a string out of another string
2
3const str = 'Mozilla';
4
5console.log(str.substring(1, 3));
6// expected output: "oz"
7
8console.log(str.substring(2));
9// expected output: "zilla"
10
1let str = "abcdefghi"
2// index-> 012456789
3
4// str.slice(±start, ±end)
5console.log(str.slice(2, 5)) // cde
6console.log(str.slice(-5, -3)) // ef
7
8// str.subString(+start, +end) // can't take -ve index
9console.log(str.substring(2, 5)) // cde
10console.log(str.substring(5, 2)) // cde
11
12// str.substr(±start, length)
13console.log(str.substr(2, 5)) // cdefg
1const str = 'substr';
2
3console.log(str.substr(1, 2)); // (1, 2): ub
4console.log(str.substr(1)); // (1): ubstr
5
6/* Percorrendo de trás para frente */
7console.log(str.substr(-3, 2)); // (-3, 2): st
8console.log(str.substr(-3)); // (-3): str
9
1const str = 'Mozilla';
2
3console.log(str.substring(1, 3));
4// expected output: "oz"
5
6console.log(str.substring(2));
7// expected output: "zilla"