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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T19:05:26+00:00 2026-06-06T19:05:26+00:00

I have a json file that I’m trying to get values out of. One

  • 0

I have a json file that I’m trying to get values out of. One object is nested inside another in this file. I can isolate the top level values, but not the nested values. It must be a syntax issue. Here’s what I’m using.

This is the json:

{
    "total": [
        [
            {
                "votes": "79,060"
            },
            {
                "percent": "11%"
            },
            {
                "winner": "0"
            }
        ],
        [
            {
                "votes": "167,800"
            },
            {
                "percent": "22%"
            },
            {
                "winner": "0"
            }
        ],
        [
            {
                "votes": "51,519"
            },
            {
                "percent": "7%"
            },
            {
                "winner": "0"
            }
        ],
        [
            {
                "votes": "297,060"
            },
            {
                "percent": "39%"
            },
            {
                "winner": "1"
            }
        ],
        [
            {
                "votes": "156,787"
            },
            {
                "percent": "21%"
            },
            {
                "winner": "0"
            }
        ]
    ],
    "useWinnerColors": 1,
    "timestamp": "3:00 p.m. April 26",
    "candidateCount": 5
}

When I write:

console.log(json.candidateCount);

I get the right answer (5).

But when I write:

console.log(json.total[0][1]);

I get Object { percent=”11%”}.

And when I write:

console.log(json.total[0].votes);

I get undefined.

How do I isolate the value of the items in “total”, please?

  • 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-06T19:05:27+00:00Added an answer on June 6, 2026 at 7:05 pm

    You’re getting undefined because json.total[0] is itself, an array. You need to isolate the specific array inside json.total[0]. So you would need to do something like json.total[0][0].votes or json.total[0][1].votes.

    I think a better structure for your JSON would be something like this:

    {"total": [    
       {
          "votes": "79,060"
          "percent": "11%"
          "winner": "0",
       },
       ...
       {
          "votes": "156,787",
          "percent": "21%",
          "winner": "0"
       }], 
       "useWinnerColors": 1,
       "timestamp": "3:00 p.m. April 26",
       "candidateCount": 5
    }
    

    Now you can do json.total[0].votes.

    You don’t need to create an array where each entry is a name-value pair. You can directly use an associative-array.

    EDIT: To iterate over your associative array, use for..in along with hasOwnProperty(). The hasOwnProperty() check will prevent you from iterating over properties that it has inherited (some third-party libraries pollute the namespace):

    var map = json.total[0];
    for(var prop in map) if(map.hasOwnProperty(prop)) {
       var value = map[prop];
       ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a text file that contains cached data in JSON format. I'm trying
I have this swf (flash) file that provides the json that needs to be
I have a Json file that looks like this: [ { field:val }, ....
I have a manifest.json file that looks like this: { name: Zend Debugger Extension,
i have a JSON file that i'm trying to parse using SBJson. the response
I have json file that I have exported using TexturePacker, and it produces this
I have a data dump in a JSON file that I'm trying to pull
I have an external JSON file that has this in it: { Home: [
I have a json file that looks like this: { status: 200, data: {
I have a json file I'm trying to save when btn one is clicked

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.