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