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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:17:29+00:00 2026-05-24T03:17:29+00:00

I have jQuery included so if it helps to use it, it’s available. First

  • 0

I have jQuery included so if it helps to use it, it’s available.

First the simple question:

Is there a way to check if several vars are all equal to each other?

I can use the transitive relation logic and do

if ((a == b) && (b == c)) && (c == d)) ... {

to avoid checking every variable against EACH other, but I think there should be a fancier way to do this.

If you can answer this first part only, it would be much appreciated.

Now, the tricky part…
I have a variable amount of variables (between 1 and 5)
I know that their value can be any of 200 possible values from a DDBB.

What would be the best way to know how many instances of each value I have within those variables?

For example…

If I have…

var1 = VALUE_A;
var2 = VALUE_A;
var3 = VALUE_B;
var4 = VALUE_Z;
var5 = VALUE_Z;

… i want to get something like:

result["VALUE_A"] => 2
result["VALUE_B"] => 1
result["VALUE_Z"] => 2

///////////////////////////
OR if i have…

var1 = VALUE_A;
var2 = VALUE_C;
var3 = VALUE_B;

… get:

result["VALUE_A"] => 1
result["VALUE_C"] => 1
result["VALUE_B"] => 1

///////////////////////////
OR if i have…

var1 = VALUE_A;
var2 = VALUE_A;
var3 = VALUE_A;
var4 = VALUE_C;
var5 = VALUE_C;

… get:

result["VALUE_A"] => 3
result["VALUE_C"] => 2

///////////////////////////
OR if i have…

var1 = VALUE_A;
var2 = VALUE_A;
var3 = VALUE_A;

… get:

result["VALUE_A"] => 3

Hope I was clear. Examples were the only way I could think of explaining clearly.
If this is too complex for Javascript or processing so many possible values up to times 5 can make the browser slow I can do it in PHP and get the result via AJAX but I’d rather not.

  • 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-24T03:17:29+00:00Added an answer on May 24, 2026 at 3:17 am

    Would something like this do?

    function countOccurrences(arr) {
        var result = {};
        $.each(arr, function(index, value) {
            if (!result[value])
                result[value] = 1;
            else
                result[value]++;
        });
        return result;
    }
    

    This function accepts an array of the values, and returns an object whose keys are the elements and values are the number of occurrences of each.

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

Sidebar

Related Questions

I have a simple page that loads content dynamically. I use the jQuery load
I have included Zend_Form_Element_Hash into a form multiplecheckbox form. I have jQuery set to
I have a fancy web page with lots on JQuery included. Currently i am
I'm trying to use JQuery to check upon submission if a field input has
I most likely have the same problem as in this question: Weird Chrome prototype/jQuery
I am trying to use jQuery's fancy autocomplete function but I have a problem
I have included jquery and jqueryui from google api as follows <script type=text/javascript src=http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.5/jquery-ui.min.js></script>
How have you guys handled working with jQuery includes <script type=text/javascript src=jquery.js></script> in Asp.Net
I have this code <html> <include jquery> <script> function crea() { var html =
I have a page being loaded with jQuery. The initial load includes 100 records

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.