there is an array
var arr = [ "/", "/some/[foo]" ] You need to do a search, but instead of foo there can be anything, for example:
var index = "/some/32" there is an array
var arr = [ "/", "/some/[foo]" ] You need to do a search, but instead of foo there can be anything, for example:
var index = "/some/32" If I understand correctly, you need to find out if there is a certain sequence of characters in the array of strings. Then the following will do:
var arr = ['text', 'text123']; findSome('123', arr); findSome('34', arr); function findSome(text, array) { return array.some(function (str) { return str.indexOf(text) !== -1; }); } If we are just talking about finding a string in an array, then includes() suffices, and indexOf() possible, without some() .
var arr = ['text1', 'text2']; var text = 'text2'; arr.includes(text); // arr.indexOf(text) !== -1 Source: https://ru.stackoverflow.com/questions/864803/
All Articles