JavaScript 判断字符串是否包含指定字符
JavaScript 大约 493 字ES6 之前
indexOf()
,返回-1
表示不包含该字符串。
var str = "Hello world";
var result = str.indexOf("world");
console.log(result) // 6
ES6
提供了三种新方法。
includes()
返回布尔值,表示是否找到了参数字符串。
var str="Hello world";
var result=str.includes("world");
console.log(result) // true
startsWith()
返回布尔值,表示参数字符串是否在原字符串的头部。
var str="Hello world";
var result=str.startsWith("Hello");
console.log(result) // true
endsWith()
返回布尔值,表示参数字符串是否在原字符串的尾部。
var str="Hello world";
var result=str.endsWith("world");
console.log(result) // true
阅读 81 · 发布于 2022-07-04
————        END        ————
Give me a Star, Thanks:)
https://github.com/fendoudebb扫描下方二维码关注公众号和小程序↓↓↓

昵称:
随便看看
换一批
-
SQLSTATE[HY000]: General error: 1205 Lock wait timeout exceeded; try restarting transaction阅读 1433
-
JMeter 使用 Response Assertion 判断接口请求是否成功阅读 1008
-
Spring Boot 启动后首次请求比较慢阅读 1123
-
OpenResty 中使用 lua-resty-http 完成 HTTP 请求阅读 10000
-
Windows 使用 Wireshark 抓取本地数据包阅读 1517
-
定时清理 MongoDB 历史数据阅读 2901
-
IDEA Debug 人为修改数值模拟数据不一致情况阅读 663
-
Linux 添加 iptables 防火墙规则阅读 1704
-
设计模式之备忘录模式阅读 1705
-
HTML inpu t和 textarea 在 iOS 系统上有阴影解决办法阅读 1040