javascript - 如何在 JavaScript 中使用 Python 字符串索引?
问题描述
在 Python 中,您可以执行以下操作:
string = "Hello World"
print(string[2:5])
# llo
JavaScript 中的等价物是什么?
解决方案
尝试使用该slice
功能:
var str = "Hello world!";
var res = str.slice(2, 5);
console.log(res) // llo
推荐阅读
- java - iText7 Image Transparency
- android - Recyler 视图没有遍历所有项目,它只显示一个项目
- kernel - I2C 驱动程序更改以识别多条总线
- angular - Ag-grid 在调整屏幕大小时防止水平滚动
- sql - 使用过滤器分组
- python - 基于字典值的 Matplotlib 条形图颜色
- javascript - 地理定位移动测试,无需 https 即可进行网络地理定位
- sql-server - 通过脚本从模板创建数据库
- c# - 后台线程更新值,在非 UI 线程上调用 OnPropertyChanged,因此出现错误
- php - Codeigniter 3中控制器的问题加载视图