Finding multiple values in a string Jquery / Javascript

Posted by user257503 on Stack Overflow See other posts from Stack Overflow or by user257503
Published on 2011-01-10T15:34:35Z Indexed on 2011/01/10 15:53 UTC
Read the original article Hit count: 223

I have a three strings of categories

  1. "SharePoint,Azure,IT";
  2. "BizTalk,Finance";
  3. "SharePoint,Finance";

I need to find a way to check if a string contains for example "SharePoint" and "IT", or "BizTalk" and "Finance". The tests are individual strings themselces.

How would i loop through all the category strings (1 - 3) and only return the ones which have ALL instances of the souce.

i have tried the following

            function doesExist(source, filterArray)
        {
            var substr = filterArray.split(" ");

            jQuery.each(substr, function() {
                var filterTest = this;                              
                if(source.indexOf(filterTest) != -1 )
                {                       
                    alert("true");
                    return true;
                }else
                {   
                    alert("false");
                    return false;           
                }                                       
            });
        }

with little success...the code above checks one at a time rather than both so the results returned are incorrect. Any help would be great.

Thanks

Chris

UPDATE: here is a link to a work in progress version..http://www.invisiblewebdesign.co.uk/temp/filter/#

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery