【发布时间】:2020-10-04 12:32:04
【问题描述】:
在 Python 中,您可以执行以下操作:
string = "Hello World"
print(string[2:5])
# llo
JavaScript 中的等价物是什么?
【问题讨论】:
标签: javascript python string slice
在 Python 中,您可以执行以下操作:
string = "Hello World"
print(string[2:5])
# llo
JavaScript 中的等价物是什么?
【问题讨论】:
标签: javascript python string slice
尝试使用slice函数:
var str = "Hello world!";
var res = str.slice(2, 5);
console.log(res) // llo
【讨论】:
您可以同时使用slice 或substring:
const str = "Hello world!";
console.log(str.substring(2, 5));
console.log(str.slice(2, 5));
【讨论】: