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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:50:19+00:00 2026-06-13T04:50:19+00:00

(forgive me if I use slightly incorrect language – feel free to constructively correct

  • 0

(forgive me if I use slightly incorrect language – feel free to constructively correct as needed)

There are a couple posts about getting data from JSON data of siblings in the returned object, but I’m having trouble applying that information to my situation:

I have a bunch of objects that are getting returned as JSON from a REST call and for each object with a node of a certain key:value I need to extract the numeric value of a sibling node of a specific key. For example:

For the following list of objects, I need to add up the numbers in “file_size” for each object with matching “desc” and return that to matching input values on the page.

{"ResultSet":{

  Result":[

    {
        "file_size":"722694",
        "desc":"description1",
        "format":"GIF"
    },

    {
        "file_size":"19754932",
        "desc":"description1",
        "format":"JPEG"
    },

    {
        "file_size":"778174",
        "desc":"description2",
        "format":"GIF"
    },

    {
        "file_size":"244569996",
        "desc":"description1",
        "format":"PNG"
    },

    {
        "file_size":"466918",
        "desc":"description2",
        "format":"TIFF"
    }

  ]

}}
  • 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-13T04:50:20+00:00Added an answer on June 13, 2026 at 4:50 am

    You can use the following function:

    function findSum(description, array) {
        var i = 0;
        var sum = 0;
    
        for(i = 0; i < array.length; i++) {
            if(array[i]["desc"] == description && array[i].hasOwnProperty("file_size")) {
                sum += parseInt(array[i]["file_size"], 10);
            }
        }
    
        alert(sum);
    }
    

    And call it like this:

    findSum("description1", ResultSet.Result);
    

    To display an alert with the summation of all "description1" file sizes.

    A working JSFiddle is here: http://jsfiddle.net/Q9n2U/.


    In response to your updates and comments, here is some new code that creates some divs with the summations for all descriptions. I took out the hasOwnProperty code because you changed your data set, but note that if you have objects in the data array without the file_size property, you must use hasOwnProperty to check for it. You should be able to adjust this for your jQuery .each fairly easily.

    var data = {};
    var array = ResultSet.Result;
    
    var i = 0;
    var currentDesc, currentSize;
    var sizeDiv;
    var sumItem;
    
    //Sum the sizes for each description
    for(i = 0; i < array.length; i++) {
        currentDesc = array[i]["desc"];
        currentSize = parseInt(array[i]["file_size"], 10);
    
        data[currentDesc] =
            typeof data[currentDesc] === "undefined"
            ? currentSize
            : data[currentDesc] + currentSize;
    }
    
    //Print the summations to divs on the page
    for(sumItem in data) {
        if(data.hasOwnProperty(sumItem)) {
            sizeDiv = document.createElement("div");
            sizeDiv.innerHTML = sumItem + ": " + data[sumItem].toString();
            document.body.appendChild(sizeDiv);
        }
    }
    

    A working JSFiddle is here: http://jsfiddle.net/DxCLu/.

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

Sidebar

Related Questions

(Please forgive my ignorance on Excel add-ins, and feel free to correct my teminology
I'm new to using Servlets so please forgive me if I use incorrect terminology.
Forgive my ignorance, but I am somewhat new to shell scripting and the use
First, please forgive my bad english ;) I want to use the windows function
Is there any method to use bubbles programmatically for give suggestions in UITextfield.
Forgive me if this is the wrong place to ask this, I feel like
I don't normally use eclipse, so please forgive my ignorance. Actually to analyze trace
everyone. Firstly, forgive my poor English #_# I use ubuntu 11.10 now. And I
Please forgive if i use terminology wrong, but i'm new to java-web development and
First, please forgive and point out if I am to use some other protocol

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.