首页 > 其他 > 详细

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

时间:2019-09-28 09:17:36      阅读:98      评论:0      收藏:0      [点我收藏+]
      <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>

 

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

原文:https://www.cnblogs.com/150536FBB/p/11601412.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!