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

  • Home
  • SEARCH
  • 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 8633101
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:26:37+00:00 2026-06-12T09:26:37+00:00

I want to return the count of each property. For example, I would like

  • 0

I want to return the count of each property. For example, I would like to return how many people are in each group. So for the following JSON, it would return 3 people in Group 1, 3 people in Group 3, 2 people in Group 16, etc.

I’m looking for a Javascript or jQuery solution.

Note: I do not need help parsing the JSON. I only need help in finding the counts of each occurrence.

{
"people":[
    {"id":"0","name":"Mike Johnson","group":1},
    {"id":"1","name":"Bob Smith","group":2},
    {"id":"2","name":"Richard Thomas","group":3},
    {"id":"3","name":"Betty White","group":16},
    {"id":"4","name":"Tim Thompson","group":3},
    {"id":"5","name":"Carl Lewis","group":16},
    {"id":"6","name":"Kathy Towers","group":3},
    {"id":"7","name":"Billy Bob","group":1},
    {"id":"8","name":"Sally Bailey","group":1}
    ]
}
  • 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-06-12T09:26:38+00:00Added an answer on June 12, 2026 at 9:26 am

    Like some comment said, you have to loop through the “people” array. It’s easy to turn this “feature” into a function like I have so you can just specify the group you’re searching for, and get back the number of people.

    http://jsfiddle.net/UdhRW/

    var obj = {
      "people": [
        {"id":"0","name":"Mike Johnson","group":1},
        {"id":"1","name":"Bob Smith","group":2},
        {"id":"2","name":"Richard Thomas","group":3},
        {"id":"3","name":"Betty White","group":16},
        {"id":"4","name":"Tim Thompson","group":3},
        {"id":"5","name":"Carl Lewis","group":16},
        {"id":"6","name":"Kathy Towers","group":3},
        {"id":"7","name":"Billy Bob","group":1},
        {"id":"8","name":"Sally Bailey","group":1}
        ]
    };
    
    function getCount(group) {
        var count = 0;
        for (var i = 0; i < obj.people.length; i++) {
            if (obj.people[i].group == group) {
                count++;
            }
        }
        return count;
    }
    
    getCount(1);   // should return 3
    

    If obj isn’t global, you can pass it to the function and it would be like this:

    function getCount(arr, group) {
        var count = 0;
        for (var i = 0; i < arr.length; i++) {
            if (arr[i].group == group) {
                count++;
            }
        }
        return count;
    }
    
    getCount(obj.people, 1);   // should return 3
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to return a simple json result, something like: { 12323: true }
I want to return the Model (data) of a controller in different formats (JavaScript/XML/JSON/HTML)
I want to return some files in a HttpResponse and I'm using the following
I want to create a JSON array like this: var ddBasic = [ {
I have the following query that works like i want it to, except i
I would like my MSSQL statement to return the string 'multiple' if multiple jobs
I have a query which returns two rows of data as count. I want
I want to return a specific message on error of an ajax request. [WebMethod]
I want to return a private field from a remoted object but i get
I want to return a set of values from function till the point they

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.