Phi*_*ilG 9 javascript regex arrays
我有这个数组:
array = ['S2B_MSIL1C_20180310T041559_N0206_R090_T46QEK_20180310T075716.SAFE'];
这个正则表达式:
regex = new RegExp('S2B_MSIL1C_20180310T041559_N0206_R090_T46QEK_20180310T075716' + '.SAFE','g');
当我使用时array.includes(regex);,false返回。我错过了什么吗?
TKo*_*KoL 19
用 Array.some
var yourRegex = /pattern/g ;
var atLeastOneMatches = array.some(e => yourRegex.test(e));
Run Code Online (Sandbox Code Playgroud)
Array.some在数组中的第一个返回 true 后返回 true。如果它通过 no 遍历整个数组true,则返回 false。