<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<script>
const cf = "chenfeng";
//以前的检索字符
if (cf.indexOf("f") != -1) {
console.log("找到了");
}
//includes(), 返回的是布尔
console.log(cf.includes('e'));
console.log(cf.includes('e', 3));
console.log(cf.includes('e', 5));
console.log(cf.includes('e', 6));
// startsWith()判断开头,可以用于区分大小写
console.log(cf.startsWith('c'))
console.log(cf.startsWith('f'))
</script>
</body>
</html>
js 检索字符串技巧
于 2022-02-25 23:19:13 首次发布