It’s as simple as iterating the array and looking for the regexp
function searchStringInArray (str, strArray) {
for (var j=0; j<strArray.length; j++) {
if (strArray[j].match(str)) return j;
}
return -1;
}
Edit – make str
as an argument to function.
More Related Contents:
- In javascript, how do you search an array for a substring match
- Why Array.indexOf doesn’t find identical looking objects
- javascript search array of arrays
- Search array of objects for entry matching variable and check if it matches other fields
- Get the item that appears the most times in an array
- How to find a value in an array of objects in JavaScript?
- Find closest date in array with JavaScript
- Array.prototype.fill() with object passes reference and not new instance
- JavaScript: Difference between .forEach() and .map()
- Why can I add named properties to an array as if it were an object?
- How to extend an existing JavaScript array with another array, without creating a new array
- Is the order of elements in a JSON list preserved?
- JavaScript: How to join / combine two arrays to concatenate into one array?
- Sum JavaScript object propertyA values with the same object propertyB in an array of objects
- Merge 2 arrays of objects
- Convert string with commas to array
- How might I extract the property values of a JavaScript object into an array?
- Sampling a random subset from an array
- Comparing two arrays of objects, and exclude the elements who match values into new array in JS
- How to check if a string array contains one string in JavaScript? [duplicate]
- Count duplicates within an Array of Objects
- MongoDB select where in array of _id?
- How can I perform an inner join with two object arrays in JavaScript?
- How to get the first element of an array?
- How to remove duplicates from a two-dimensional array? [closed]
- Javascript – sorting array by multiple criteria
- spread operator vs array.concat()
- How to get an Array with jQuery, multiple with the same name
- How can I loop through enum values for display in radio buttons? [duplicate]
- Using jQuery inArray with array of JavaScript Objects