Is there a javascript method to find substring in an array of strings?

前端 未结 5 1219
醉话见心
醉话见心 2021-01-26 08:58

Suppose my array is [\"abcdefg\", \"hijklmnop\"] and I am looking at if \"mnop\" is part of this array. How can I do this using a javascript method?

I tried this and it

5条回答
  •  北荒
    北荒 (楼主)
    2021-01-26 09:33

    a possible solution is filtering the array through string.match

    var array= ["abcdefg", "hijklmnop"];
    
    var res = array.filter(x => x.match(/mnop/));
    
    console.log(res)

提交回复
热议问题