Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3487546
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T11:09:44+00:00 2026-05-18T11:09:44+00:00

I have a peculiar issue I’m dealing with. I’ll start off vague and if

  • 0

I have a peculiar issue I’m dealing with. I’ll start off vague and if anyone needs more detail I can give background on the project.

I have a selected ID (selected from a checkbox): 161

And I have many rows of IDs like so:

["161", "165", "573", "190", "150", "283"] // this one would be it
["160", "311", "793", "309", "301"]
["161", "165", "395", "306"] // this one would be it
["160", "311", "668", "191", "216", "301"]

I need to identify out of the rows of IDs above, which ones have the ID that has been selected. This isn’t so difficult, I can loop through each row of IDs (looping through the actual array) and do thisIDList[i] == selectedID.

Problem I’m having is when more than one ID has been selected: ["161", "306"]

Now I need to loop through the rows and identify which rows has both of the selected IDs.

["161", "165", "573", "190", "150", "283"] // wouldn't be it
["160", "311", "793", "309", "301"]
["161", "165", "395", "306"] // this one would be it
["160", "311", "668", "191", "216", "301"]

And so on. There can be anywhere from 1 to 5 or 6 IDs selected: ["161", "306", "216", "668"]

Can someone point me in the right direction? I think this is basically like comparing two lists where each item in List A needs to found in List B.


edit

I should add that the row can contain other IDs not found in the selected list. So if the selected IDs was ["161", "306"], then ["161", "165", "395", "306"] would be a match still, even though it contains 165 and 395.


edit

Going to update and give a bit more info. I have a list of radio buttons:

<input type="checkbox" name="filter" value="301" />
<input type="checkbox" name="filter" value="161" />
<input type="checkbox" name="filter" value="573" />
<input type="checkbox" name="filter" value="190" />

I have an unordered list, each list has a data attribute (I’m using the metadata plugin):

<ul>
    <li data="{attrID: '160,197,161,194,195,190,162' }">Lorem Ipsum</li>
</ul>

When a radio button is clicked:

// set the selected IDs
selectedIds = []; 
$("input[name=filter]:checked").each(function(){ 
     selectedIds.push(this.value);
});

// loop through each list                   
$('ul li').each(function () {  

    // get and set the metadata for the attrID key
    meta = $(this).metadata();
    idList = meta.attrID;   

    // find out if the selected IDs are found in this idList
    var isMatch = matches(selectedIds,idList);

    console.log(isMatch);

    // my plan was to do this
    if(isMatch){
        // do something with this list item
    }


});
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T11:09:44+00:00Added an answer on May 18, 2026 at 11:09 am

    This uses the inArray function from jQuery. It returns an array containing the indices of the sets that contain all elements of the target set. If your sets are relatively small, as in your example, it should be fast enough.

    function matches( target, sets )
    {
        var matches= [];
        for (var i = 0, setsLen = sets.length; i < setsLen; ++i ) {
            if (isSubset(target,sets[i])) {
               matches.push(i);
            }
        }
        return matches;
    }
    
    function isSubset( target, set )
    {
        for (var j = 0, targetLen = target.length; j < targetLen; ++j) {
             if ($.inArray(target[j], set) < 0) {
                 return false;
             }
        }
        return true;
    }
    

    A little test script based on your data:

    $(function(){
        var sets = [
                      ["161", "165", "573", "190", "150", "283"],
                      ["160", "311", "793", "309", "301"],
                      ["161", "165", "395", "306"],
                      ["160", "311", "668", "191", "216", "301"]
        ];
    
        alert( matches( [ "161" ], sets ) );
        alert( matches( [ "161","306" ], sets ) );
     });
    

    EDIT: I updated my example based on your additions. I think you’d only need to use the isSubset function. I’ll leave the rest of the answer for context.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am stuck with a peculiar issue here. I have a script that basically
We are facing a peculiar issue at the moment and we have no clue
So very peculiar spring httpinvoker issue going on. I have a soap web service
I am dealing with a very peculiar problem at the moment: I have an
I have a very peculiar problem. In the VS2010 Server Explorer, I can connect
I have a peculiar problem here and I can't by my life figure out
I have a peculiar problem and I am not sure if anyone had come
I have a peculiar issue which is giving me headaches... The following code works
I have a very peculiar issue debugging some code. In the first iteration of
i seem to have a rather peculiar issue with my overloaded constructors in the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.