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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:46:52+00:00 2026-06-14T15:46:52+00:00

I retrieve some data off an API and I append it as such: if

  • 0

I retrieve some data off an API and I append it as such:

if (jsontext == '[]') {
    return false
} else {

    var newTr = '';
    for (var i = 0; i < json.length; i++) {
        newTr += (' / ' + json[i].date + ' ' + json[i].price);

    }

    console.log(newTr);

}

which gives me a huge list of results as such:

/ 07-09-2012 72.60 / 11-09-2012 194.98 / 03-09-2012 94.82 / 04-09-2012 187.56 / 31-10-2012 72 / 18-09-2012 204.75 / 26-09-2012 243.73 / 14-09-2012 86.40 / 20-09-2012 91.63 / 28-09-2012 96.56 / 01-09-2012 94.62 / 17-09-2012 94.86 / 17-09-2012 83.25 / 12-09-2012 94.85 / 18-09-2012 94.86 / 18-09-2012 68.74 / 21-09-2012 94.86 / 21-09-2012 94.86 / 24-09-2012 144.23 / 28-09-2012 92.77 / 30-09-2012 92.77 / 28-09-2012 92.77 / 13-09-2012 151.12 / 03-09-2012 125.80 / 05-09-2012 92.61 / 05-09-2012 95.54 / 12-09-2012 94.59 / 12-09-2012 94.59 / 13-09-2012 125.83 / 18-09-2012 109.38

and keep’s going.

How can I take the sum of the pricing for the month 09?

The date format is dd-mm-yyyy.

  • 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-14T15:46:53+00:00Added an answer on June 14, 2026 at 3:46 pm

    I assume that what you have is a string like below,

    "/ 07-09-2012 72.60 / 11-09-2012 194.98 / 03-09-2012 94.82 / 04-09-2012 187.56 / 31-10-2012 72 / 18-09-2012 204.75 / 26-09-2012 243.73 / 14-09-2012 86.40 / 20-09-2012 91.63 / 28-09-2012 96.56 / 01-09-2012 94.62 / 17-09-2012 94.86 / 17-09-2012 83.25 / 12-09-2012 94.85 / 18-09-2012 94.86 / 18-09-2012 68.74 / 21-09-2012 94.86 / 21-09-2012 94.86 / 24-09-2012 144.23 / 28-09-2012 92.77 / 30-09-2012 92.77 / 28-09-2012 92.77 / 13-09-2012 151.12 / 03-09-2012 125.80 / 05-09-2012 92.61 / 05-09-2012 95.54 / 12-09-2012 94.59 / 12-09-2012 94.59 / 13-09-2012 125.83 / 18-09-2012 109.38"
    

    If that is the case then you need to parse the string to calculate the sum by month.

    DEMO: http://jsfiddle.net/pBNNt/

    Full Code:

    var resultArr = result.split('/');
    var results = {}; //sum by month
    for (var i = 0; i < resultArr.length; i++) {    
        if ( resultArr[i].length >= 11) { //it has date
            var resultTkn = resultArr[i].split(' ');
    
            if (resultTkn[1].length == 10) { //it is a date
                var date = resultTkn[1].split('-');
                var sum = 0;
                if (results.hasOwnProperty(date[1])) {
                    sum = results[date[1]];
                }
    
                sum += parseFloat(resultTkn[2]);
                results[date[1]] = sum;
            }
        }
    }
    

    Now you can access the sum by month using the results objects. results["09"] returned 3305.93

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

Sidebar

Related Questions

Im trying to retrieve some data from JSON object which holds location information such
I am using jQuery's $.post function to retrieve some data from a php file,
My app is calling a web service to retrieve some data, and I want
I'm working on an app that needs to retrieve some data from a server.
So, I'm trying to use Doctrine to retrieve some data. I have some basic
I wrote a C++ program to retrieve some text data from MS-Active Directory and
I have retrieve some data from table. form array like I want array is..
Using getJSON to retrieve some data which I am utf8 encoding on the server-side
Im sending over some json data and assigning to a hidden field using: @Html.Hidden(hidden-places,
I've got a page that retrieves a bunch of locations and some data about

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.