1

In Python, you can do something like this:

string = "Hello World"
print(string[2:5])
# llo

What is the equivalent of that in JavaScript?

Gabio
  • 8,225
  • 3
  • 8
  • 26
leo848
  • 344
  • 3
  • 13

2 Answers2

4

Try using the slice function:

var str = "Hello world!"; 
var res = str.slice(2, 5); 
console.log(res) // llo
Nick
  • 123,192
  • 20
  • 49
  • 81
Gabio
  • 8,225
  • 3
  • 8
  • 26
1

You can use both slice or substring:

const str = "Hello world!";

console.log(str.substring(2, 5));
console.log(str.slice(2, 5));