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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:38:07+00:00 2026-06-14T20:38:07+00:00

I’m trying to create 2 arrays from a JSON feed, and then calculate the

  • 0

I’m trying to create 2 arrays from a JSON feed, and then calculate the average value of both. First, the way I will the arrays is like this:

$.getJSON('jasonfile.json', function(rawdata) {
  var array_one = [];
  var array_two = [];

  $.each(rawdata, function(i, entry) {
    if(entry["geslacht"] == "Man") {
      array_one.push(entry["key"]);
    else {
      array_two.push(entry["key"]);
    }
  )};
)};

This works fine, except when I look into my console array_one seems to be somekind of array of objects, and `array_two seems to be a normal array. Thus when I try to calculate the average of the two like so:

var array_one_total = 0;
$.each(array_one, function() {
  array_one_total += this;
});

array_one_average = array_one_total/array_one.length;

I get a right and a wrong value. array_one logs “NaN” like this in my console, while array_two displays the correct average:

Javascript weird result in console

It seems to be a problem with the format of the array, but I can’t understand why is returns the second value correct, as I’m using the same method for both of them.

Here’s in image of what happens if I log both arrays directly to the console, and you can see the different ways they are displayed:

console log

Well I got a lot of responses asking for my entire code, the number of arrays make it harder to read but here it is:

$.getJSON('propedeuse201112.json', function(rawdata) {
  var ucd_male = [];
  var ucd_female = [];
  var internetstandaarden_male = [];
  var internetstandaarden_female = [];
  var understanding_design_male = [];
  var understanding_design_female = [];
  var taal_in_context_male = [];
  var taal_in_context_female = [];
  var vormgeving_male = [];
  var vormgeving_female = [];
  var marketing_male = [];
  var marketing_female = [];
  var h_en_c_male = [];
  var h_en_c_female = [];
  var programmeren_male = [];
  var programmeren_female = [];
  var m_en_i_male = [];
  var m_en_i_female = [];
  var mediageschiedenis_male = [];
  var mediageschiedenis_female = [];
  var business_mapping_male = [];
  var business_mapping_female = [];
  var plug_and_play_male = [];
  var plug_and_play_female = [];
  var slc_male = [];
  var slc_female = [];

  $.each(rawdata, function(i, entry) {
    if(entry["geslacht"] == "Man") {
      ucd_male.push(entry["ucd"]);
      internetstandaarden_male.push(entry["internetstandaarden"]);
      understanding_design_male.push(entry["understanding design"]);
      taal_in_context_male.push(entry["Taal in context"]);
      vormgeving_male.push(entry["Vormgeving"]);
      marketing_male.push(entry["Marketing"]);
      h_en_c_male.push(entry["H&C"]);
      programmeren_male.push(entry["Programmeren"]);
      m_en_i_male.push(entry["M&I"]);
      mediageschiedenis_male.push(entry["Mediageschiedenis"]);
      business_mapping_male.push(entry["Business Mapping"]);
      plug_and_play_male.push(entry["Plug & Play"]);
      slc_male.push(entry["SLC"]);
    } else {
      ucd_female.push(entry["ucd"]);
      internetstandaarden_female.push(entry["internetstandaarden"]);
      understanding_design_female.push(entry["understanding design"]);
      taal_in_context_female.push(entry["Taal in context"]);
      vormgeving_female.push(entry["Vormgeving"]);
      marketing_female.push(entry["Marketing"]);
      h_en_c_female.push(entry["H&C"]);
      programmeren_female.push(entry["Programmeren"]);
      m_en_i_female.push(entry["M&I"]);
      mediageschiedenis_female.push(entry["Mediageschiedenis"]);
      business_mapping_female.push(entry["Business Mapping"]);
      plug_and_play_female.push(entry["Plug & Play"]);
      slc_female.push(entry["SLC"]);
    }

  });

  var ucd_male_total = 0;
  $.each(ucd_male, function(index,item) {
    ucd_male_total += parseInt(item);
  });
  ucd_male_average = ucd_male_total/ucd_male.length;

  var ucd_female_total = 0;
  $.each(ucd_female, function(index,item) {
    ucd_female_total += parseInt(item);
  });
  ucd_female_average = ucd_female_total/ucd_female.length;

  console.log(ucd_male);
  console.log(ucd_female);  

});

Below the structure of rawdata (this is one entry):

[{"id":1,"geslacht":"Vrouw","totaal punten":60,"project      1":9,"ucd":6,"internetstandaarden":7,"understanding design":7,"Teamproject deel 1":6,"Taal in context":6,"Vormgeving":7,"Marketing":6,"Students in Motion":7,"Teamproject deel 2":7,"H&C":6,"Programmeren":7,"M&I":7,"Project 3":6,"Mediageschiedenis":6,"Business Mapping":7,"Plug & Play":7,"SLC":7,"Studieregie":8,"plaats":"JOPPE","geboortejaar":1990,"vooropleiding":"HAVO","vooropleiding afgerond in":2009},
  • 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-14T20:38:08+00:00Added an answer on June 14, 2026 at 8:38 pm

    You have several critical typos in your code

     $.each(rawdata, function(i, entry) {
        if(entry["geslacht"] == "Man") {
          array_one.push(entry["key"]);
        else {
          array_one.push(entry["key"]); /* <===== should be array_two*/
        }
      )};
    
    var array_one_total = 0;
    $.each(array_one, function() {
      array_one += this;/* <===== should be array_one_total*/
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I am trying to understand how to use SyndicationItem to display feed which is
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to create an if statement in PHP that prevents a single post
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,

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.