检查javascrpit中给定字符串数组的字符串匹配

编程入门 行业动态 更新时间:2024-10-14 04:27:50
本文介绍了检查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中给定字符串数组的字符串匹配

本文发布于:2023-10-28 04:37:19,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1535542.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符串   数组   javascrpit

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!