本文介绍了检查javascrpit中给定字符串数组的字符串匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图将我的字符串与给定的字符串数组匹配,但是下面的代码不起作用,是否有任何建议可能有帮助,下面的代码就是我试过的
i trying to match my string with given array of string but this below code is not working,is any suggestion might be help , below code is what i have tried
let myLongString = 'jkjdssfhhabf.pdf&awersds=oerefsf'; let matcherArray = ['.pdf', '.jpg']; if (myLongString.match(matcherArray)) { return true; } else { return false; }预期输出 true 。是否有更好的解决方案可以解决这类问题谢谢。
expected output is true. is there is any better solution is there to solve this type question thank you.
推荐答案无需循环
let myLongString = 'jkjdssfhhabf.pdf&awersds=oerefsf'; console.log(/\.(jpe?g|pdf)/i.test(myLongString));
更多推荐
检查javascrpit中给定字符串数组的字符串匹配
发布评论