2017-08-29 56 views
0

我想創建一個函數,其中過濾項目在一個特定的值傳入數組中。如何爲RegEx創建價值?

目前我正在使用模板文字將RegEx的值傳遞給它的構造函數,但沒有成功。

我在做什麼錯在我的代碼?

結果應該是一個過濾的數組(在本例中爲2項)。

let data = ['Gone With the Wind', 'Star Wars: Episode IV', 'Jaws', 'Matrix', 'Matrix backstage', 'Star Wars: Episode I', 'WindWind' ]; 
 

 

 
let filter = (data, value) =>{ 
 
    //return data.filter(s => s.match(/value/i)) 
 
    return data.filter(s => s.match(`/${value}/i`)) 
 
}; 
 

 
console.log(filter(data, 'Wind'));

回答