In Python, you can do something like this:
string = "Hello World"
print(string[2:5])
# llo
What is the equivalent of that in JavaScript?
In Python, you can do something like this:
string = "Hello World"
print(string[2:5])
# llo
What is the equivalent of that in JavaScript?
Try using the slice
function:
var str = "Hello world!";
var res = str.slice(2, 5);
console.log(res) // llo
You can use both slice
or substring
:
const str = "Hello world!";
console.log(str.substring(2, 5));
console.log(str.slice(2, 5));