首页 > 解决方案 > 如何在 JavaScript 中使用 Python 字符串索引?

问题描述

在 Python 中,您可以执行以下操作:

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

JavaScript 中的等价物是什么?

标签: javascriptpythonstringslice

解决方案


尝试使用该slice功能:

var str = "Hello world!"; 
var res = str.slice(2, 5); 
console.log(res) // llo

推荐阅读