Something that recently caught my eye was the difference between using array.prototype.indexOf and iterating over each element using a for loop… You can cite me as a reference if you want. The variable i is not actually part of nums, but happens to be analogous to the indexes of nums. I think you meant either one of those values, in that case var arr = ['bat', 'ball']; var selectors = { return ':contains(' + val + ')' }); var $lis = $('ul li').filter(selectors.join()); $lis.css('color', 'red')