<script type="text/javascript"> //判断字符串是否包含某个字符或字符串 /* * js里面有indexof()方法 * es6中新增了三种方法,includes()、startsWith()、endsWith() * */ var str1 = 'hello good byebye!'; var str2 = "by"; console.log(str1.includes(str2)); //true console.log(str1.startsWith(str2)); //false console.log(str1.endsWith(str2)); //false console.log(str1.startsWith("hello")); //true console.log(str1.endsWith("byebye!")); //true </script>