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 3280760
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T19:44:26+00:00 2026-05-17T19:44:26+00:00

I previously posted this question as jquery/javascript: arrays – jquery/javascript: arrays . But since

  • 0

I previously posted this question as jquery/javascript: arrays – jquery/javascript: arrays.
But since I am a complete beginner I have formulated the question wrong and didn’t understand the answers either…. 🙁

After failing to implement the given solutions I did some more looking around I found out that I need to compare 6 arrays of possible choices and intersect them to finally display only the overlapping values.

So this is, hopely, a clearer formulation:

I have 6 questions/6 groups of radio buttons for answers. Each answer has multiple values (they can range from 1 to 38 items to be displayed in final ‘advice’). I am collecting the values of checked radios in arrays. I get 6 arrays.

How do I intersect 6 arrays in order to get one final array containing only intersecting values form all 6 choices?
How do I turn items of this final array into selectors?

Can someone please help me?
Thank you!

My script looks now like:

(function($){
  $.fn.checkboxval = function(){
      var outArr = [];
      this.filter(':checked').each(function(){
            outArr.push(this.getAttribute("value"));
      });
      return outArr;
  };
})
(jQuery);
$(function(){
  $('#link').click(function(){
    var valArr1 = $('#vraag1 input:radio:checked').checkboxval();
    var valArr2 = $('#vraag2 input:radio:checked').checkboxval();
    var valArr3 = $('#vraag3 input:radio:checked').checkboxval();
    var valArr4 = $('#vraag4 input:radio:checked').checkboxval();
    var valArr5 = $('#vraag5 input:radio:checked').checkboxval();
    var valArr6 = $('#vraag6 input:radio:checked').checkboxval();
// var newArray = $.merge(valArr1, valArr2, valArr3, valArr4, valArr5, valArr6); <- test to see if I can merge them
// $('#output').text(newArray.join(',')); <- test to see if I can join them
//$("#output").html($("#output").html().replace(/,/gi, ',#diet')); <- test to see if I can append text so it looks like the selectors of divs I need to display later
//    return false;
  });
});

my form/inputs looks like:

<input name="vraag1" type="radio" value="1a,4,5,12,13,17a,18,19,22,23,24,26,27,28,29,30,33,38,6" class="radio advice" id="vraag1-0" /><label for="vraag1-0">ja</label>
<br />
<input name="vraag1" type="radio" value="1b,1,2,3,7,8,11,9,14,15,16,17,20,21,25,31,34,35,36,37,10,32" class="radio advice" id="vraag1-1" /><label for="vraag1-1">nee</label>
<br />
<input name="vraag1" type="radio" value="1c,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,17a,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38" class="radio advice" id="vraag1-2" /><label for="vraag1-2">maakt mij niet uit</label>
  • 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-17T19:44:27+00:00Added an answer on May 17, 2026 at 7:44 pm

    Your question is still very confusing to me.

    But it appears you are getting the value from the inputs and trying to combine them. But they are all strings not arrays.

    Try just adding the strings together, then breaking them apart using split() (demo)

    $('#link').click(function() {
        var radios = '';
        $('input:radio:checked').each(function() {
            radios += $(this).val() + ',';
        })
        // remove last comma & convert to array
        radios = radios.substring(0, radios.length - 1).split(',');
        // do something with the array
        console.debug(radios);
    })
    

    Update: Ok, from your demo HTML, I couldn’t get 6 duplicates so in the demo I set it to find 3+ matches. I had to write this script to find duplicates in an array I also made it to return an associative object with the number of duplicates. There may be a better method, but this is what I came up with (updated demo):

    $(function() {
        $('#link').click(function() {
            var radios = '';
            $('input:radio:checked').each(function() {
                radios += $(this).val() + ',';
            })
            // remove last comma & convert to array
            var results = [],
                dupes = radios
                 .substring(0, radios.length - 1)
                 .split(',')
                 .getDuplicates(),
                arr = dupes[0],
                arrobj = dupes[1],
                minimumDuplicates = 6; // Change this to set minimum # of dupes to find
    
            // find duplicates with the minimum # required
            for (var i=0; i < arr.length; i++){
                if ( arrobj[arr[i]] >= minimumDuplicates ){
                    results.push(arr[i]);
                }
            }
    
            // Show id of results
            var diets = $.map(results, function(n,i){ return '#diet' + n; }).join(',');
            $(diets).show(); // you can also slideDown() or fadeIn() here
        })
    });
    
    
    /* Find & return only duplicates from an Array
     * also returned is an object with the # of duplicates found
     * myArray = ["ccc", "aaa", "bbb", "aaa", "aaa", "aaa", "aaa", "bbb"];
     * x = myArray.getDuplicates();
     * // x = [ array of duplicates, associative object with # found]
     * // x = [ ['aaa','bbb'] , { 'aaa' : 5, 'bbb' : 2 } ]
     * alert(x[0]) // x[0] = ['aaa','bbb'] & alerts aaa,bbb
     * alert(x[1]['aaa']) // alerts 5;
     */
    Array.prototype.getDuplicates = function(sort) {
        var u = {}, a = [], b = {}, c, i, l = this.length;
        for (i = 0; i < l; ++i) {
            c = this[i];
            if (c in u) {
                if (c in b) { b[c] += 1; } else { a.push(c); b[c] = 2; }
            }
            u[c] = 1;
        }
        // return array and associative array with # found
        return (sort) ? [a.sort(), b] : [a, b];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have previously posted a question about this but I did not get an
I recently posted this question about codes for a gift-card-like voucher that users can
I previously posted a question on sharing resources across assemblies using Themes/generic.xaml and the
So, I previously asked this question: Can someone help me compare using F# over
Previously I posted a question regarding multithreading. Actually my intension is to send SMS
I posted one question previously and all of them answered that there is some
This is a continuation of my previous question which I posted when I wasn't
Previously I have asked to strip text from a field and convert it to
Previously, I asked the question . The problem is the demands of our file
Previously I've asked about inserting a column into a dataset . I now have

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.