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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T19:03:26+00:00 2026-05-30T19:03:26+00:00

I am little new to javascript and I am having alittle trouble wrapping my

  • 0

I am little new to javascript and I am having alittle trouble wrapping my head around making a 2d (or maybe i might need a 3d) array in javascript.

I currently have 2 pieces of information i need to collect: an ID and a value so I created the following:

var myArray = [];

var id = 12;
var value = 44;

myArray[id]=value;

But I realized that this is not easy to loop through the array like a for loop so i was thinking of this:

myArray[myArray.length] = id;
myArray[myArray.length-1][id]=value;

I wanted to do this so that in a for loop i could get the ids and the values easily but the above only returns the value when i loop through it. Any suggestions on how to get this working or is there a better way to do this?

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-05-30T19:03:27+00:00Added an answer on May 30, 2026 at 7:03 pm

    Why not use an array of object hashes? This approach allows you to store multiple values in a key:value format:

    var myArray = [];
    var myElement = {
      id: 12,
      value: 44
    }
    
    myArray[0] = myElement;
    

    You could then loop through all of the elements in myArray like so:

    var i = 0,
        el;
    
    while (el = myArray[i++]) {
      alert(el.id + '=' + el.value);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm still new to Javascript and Jquery and am having a little trouble with
I'm having a little bit of trouble making OpenID work from within an iframe.
I'm fairly new to ASP.NET MVC, and I'm having a little trouble with scripts...
I am having a little bit of trouble making the table look like I
I'm a little new to javascript. I have a bunch of checkboxes for an
I have a little doubt about javascript, a new language that I'm studying... I
I am having a new little problem; I have a little pointer called: int
I'm new to javascript and cant get this little thing to work. (all external
Ok, so I'm REALLY new to programming and javascript, but I'm having a problem
I am having a little bit of trouble controlling the Full Calendar module as

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.