<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <script>
        var sel = ''
        var arr = ['白色', '小白', '红色', '紫色', '黑色']
        for (let index = 0; index < arr.length; index++) {
            var txt = new RegExp(sel);
            if(txt.test(arr[index])) {
                console.log(arr[index])
            } else {
                console.log('不包含')
            }
        }
    </script>
</body>
</html>

 

posted on 2019-09-29 11:28  前端入门菜鸟  阅读(362)  评论(0编辑  收藏  举报