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

前端 未结 5 1220
醉话见心
醉话见心 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:41

    Javascript does not provide what you're asking before because it's easily done with existing functions. You should iterate through each array element individually and call indexOf on each element:

    array.forEach(function(str){
        if(str.indexOf("mnop") !== -1) return str.indexOf("mnop");
    });
    

提交回复
热议问题