I've built a search function for an array of javascript objects along the lines of:
- User types text into a form input box
- Loop through object array
- If object text contains inputted text, push the object into a separate 'filtered' array
- Display filtered array
This works fine using the string search() function built into javascript ie.
if(objectarray[i].text.search(userstring)>=0){
filteredarray.push(currentobject)
};
Now the client would like to do a more advance search along the lines of:
find objects where text contains (x1 or x2) and (x3 or x4 or x5)
Where each of the x's is a word and an object would be pushed into the filtered collection when the above condition is met.
Is there a built in function which can handle this kind of complex boolean statement?