判断字符串中是否含有某一个字符或字符串


      <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>

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM