One thing you could if you have very small items (say, a few dozen) creates a regular expression matching any of them:
var match = keys.join("|") var regexp = RegExp.new(match, 'i')
Yes, I know that this is not a search for any input matching the conditions, you will need to know the input element in front, but from your question, I assume that you want to check one input element.
I donβt know if it works faster than a cycle in all terms and checks one by one, but I think it is, and it is definitely more readable.
This can be used in conjunction with jQuery grep or each methods:
var match = keys.join("|") var regexp = RegExp.new(match, 'i') // With grep var matches = $('input').grep(function(elem, idx) { return $(input).val().match(regexp) != null; }) // Or with each $('input')..each(function(idx, elem) { if ($(input).val().match(regexp) != null) { // Do stuff } });
grep selects all input fields that match any of the search conditions for later use, and each iterates over all elements to work with them immediately.
source share