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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:08:06+00:00 2026-06-13T02:08:06+00:00

I have JSON string from my php script like this: var r.co = {

  • 0

I have JSON string from my php script like this:

var r.co = {
                "A20018425":[
                                {"balance":"1390.31"},      // 1
                                {"balance":"1304.11"},      // 2
                                {"balance":"1188.11"},      // 3
                                {"balance":"1421.71"}       // 4
                            ],

                "A25005922":[
                                {"balance":"1000"},         // 1
                                {"balance":"1000.86"},      // 2
                                {"balance":"986.32"},       // 3
                                {"balance":"988.96"},       // 4
                                {"balance":"980.26"},       // 5
                                {"balance":"980.16"}        // 6 MAX 
                            ],

                "A25005923":[
                                {"balance":"1001"},         // 1
                                {"balance":"1000.16"},      // 2
                            ]           
            }

I don’t know how many AXXXXXXXX elements and how many elements it contains.
To get A elements I have use the code below:

var accounts = [];
for(var key in r.co) {
   if(r.co.hasOwnProperty(key)) {
      accounts.push(key);
   }
}

Now I know my A elements length

var accounts_length = accounts.length; // 3 for example

Now I need to know max length of elements in A:

var accounts_elements_length = [];

    for (var c = 0; c < accounts.length; c++) {   

          accounts_elements_length.push(r.co[accounts[c]].length);
    }

    var accounts_elements_length_max = accounts_elements_length.max() // 6 For example

How can I get this output array for the chart?

var outputData = [{
                        count:      1,
                        A20018425:  1390.31,
                        A25005922:  1000,
                        A25005923:  1001
                    }, {
                        count:      2,
                        A20018425:  1304.11,
                        A25005922:  1000.86,
                        A25005923:  1000.16
                    }, {
                        count:      3,
                        A20018425:  1188.11,
                        A25005922:  986.32
                    }, {
                        count:      4,
                        A20018425:  1421.71,
                        A25005922:  988.96
                    }, {
                        count:      5,
                        A25005922:  980.26
                    }, {
                        count:      6,
                        A25005922:  980.16
                    }
        }];

Thanks!

  • 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-13T02:08:07+00:00Added an answer on June 13, 2026 at 2:08 am

    Just combined your algorythms:

    var outputData = [];
    for (var key in r.co) {
       if (r.co.hasOwnProperty(key)) {
          var account_length = r.co[key].length;
          for (var c = 0; c < account_length; c++) {
              if (outputData[c] === undefined) {
                  outputData[c] = { count: c+1 };
              }
              outputData[c][key] = r.co[key][c].balance;
        }
       }
    }
    console.log(outputData);
    

    jsfiddle

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

Sidebar

Related Questions

I am getting JSON string from website. I have data which looks like this
I have a json string like this: { d: { results: [ { __metadata:
I have a JSON-encoded PHP array: <script> var registeredEmails = <?php echo(json_encode($emails)); ?>; </script>
I have the following JSON string (from wikipedia http://en.wikipedia.org/wiki/JSON ) { name:Product, properties: {
I have a json string saved in my db. When i retrieve it from
I have a JSON string that I would like to include as a value
I have this json string: $row['medium'] = {\medium\:13|17|1|14, \medium_sub\:21}; now I want to make
I am preparing and sending a JSON string from my PHP file to my
I have a JSON string(?) that I have returned from $.ajax() and named it
I have a php script http://example.com/myapp/myscript.php running on an Apache server. I call this

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.