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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:10:39+00:00 2026-06-11T21:10:39+00:00

My entire code example is below and on jsFiddle: http://jsfiddle.net/rEhvt/ . I’m trying to

  • 0

My entire code example is below and on jsFiddle: http://jsfiddle.net/rEhvt/.

I’m trying to alert() my multi-dimensional JavaScript object. If I alert() a single property of the object – it works. For example:

alert(votes['77777'].stay);

However, if I try to alert() the entire object, then I either get a lot of NULLs or blanks. I tried the following:

alert(JSON.stringify(votes));//returns lots of NULLs

alert(votes.join('\n'));//returns lots of blanks

My intention is to eventually send the object to localStorage with

localStorage['votes']=JSON.stringify(votes);

and retrieve it with

retrievedVotes=JSON.parse(localStorage['votes'])

However, I want to first be able to see the object structure. This is my first attempts at understanding multi-dimensional objects with JavaScript, so any help you can offer is greatly appreciated! Below is all of my code, which is also on jsFiddle: http://jsfiddle.net/rEhvt/.

//Movie #1
var movieID = 55555;
var stay = 'yes';

var votes = [];
votes[movieID]=[];
votes[movieID].stay = stay;

var scenes = 1;
votes[movieID].scenes = scenes; 

//Movie #2
var movieID = 77777;
var stay = 'no';

var votes = [];
votes[movieID]=[];
votes[movieID].stay = stay;

var scenes = 0;
votes[movieID].scenes = scenes; 

//Alert Single Item from votes
alert(votes['77777'].stay);

//Alert entire object
alert(JSON.stringify(votes));//returns NULLs

//Alert entire object
alert(votes.join('\n'));//returns lots of blanks
  • 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-11T21:10:40+00:00Added an answer on June 11, 2026 at 9:10 pm

    Use an object {} rather than an array []… setting votes[7777] is going to reindex the array to accommodate 7,778 elements… with lots and lots of undefined elements (which JSON.stringify() will convert to null).

    Plus, you’re setting named properties on an array:

    votes[movieID]=[];
    votes[movieID].stay = stay;
    

    Here’s a functional sample using objects (fiddle):

    var votes = {
        // Movie #1
        '55555': { 
            stay: 'yes',
            scenes: 1,
            outtakes: 0,
            enhanced: 0,
            teaser: 0
        },
        // Movie #2
        '77777': { 
            stay: 'no',
            scenes: 0,
            outtakes: 0,
            enhanced: 0,
            teaser: 0
        }   
    };
    
    console.log(votes[77777].stay);
    console.log(votes);
    

    and a 1-to-1 change in your provided code (fiddle):

    //Movie #1
    var movieID = 55555;
    var stay = 'yes';
    
    var votes = {}; // changed to {}
    votes[movieID]= {}; // changed to {}
    votes[movieID].stay = stay;
    
    var scenes = 1;
    votes[movieID].scenes = scenes; 
    var outtakes = 0;
    votes[movieID].outtakes = outtakes; 
    var enhanced = 0;
    votes[movieID].enhanced = enhanced; 
    var teaser = 0;
    votes[movieID].teaser = teaser; 
    
    //Movie #2
    var movieID = 77777;
    var stay = 'no';
    
    //var votes = []; removed
    votes[movieID]= {};  // changed to {}
    votes[movieID].stay = stay;
    
    var scenes = 0;
    votes[movieID].scenes = scenes; 
    var outtakes = 0;
    votes[movieID].outtakes = outtakes; 
    var enhanced = 0;
    votes[movieID].enhanced = enhanced; 
    var teaser = 0;
    votes[movieID].teaser = teaser; 
    
    //Alert Single Item from votes
    alert(votes['77777'].stay);
    
    //Alert entire object/array
    alert(JSON.stringify(votes));//returns NULLs​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

EDIT: The entire code and database creation script can be found from http://gitorious.org/scheator .
Below is my entire code from a User control that contains the YUI Uploader.
I am currently using a javascript code to make an entire row in my
Im working with the code below from here: http://api.jquery.com/jQuery.getJSON/ $.getJSON(http://api.flickr.com/services/feeds/photos_public.gne?jsoncallback=?, { format: json },
Trying to run the Blocking Queue example given here . Using the .NET Queue
Below is the code I tried: <script type=text/javascript> Ext.require(['*']); Ext.onReady(function() { Ext.Loader.setConfig({ enabled: true
My entire source code base is < 20MB. I want it all loaded in
this is my entire PHP code: <?php if(empty($_POST['selid'])) {echo no value selected; } else
I am using the following code to try and delete entire rows when it
For some reason my code here (this is the entire thing) doesnt actually render

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.