www.webdeveloper.com
Results 1 to 2 of 2

Thread: How to declare and initialize an array with key/values using JavaScript

  1. #1
    Join Date
    Feb 2009
    Posts
    95

    How to declare and initialize an array with key/values using JavaScript

    How to declare and initialize an array with key/values using JavaScript and then dynamically creating select dropdown and assigning key/values to the options using JavaScript?

  2. #2
    Join Date
    Dec 2002
    Location
    St. Louis, MO, USA
    Posts
    1,582
    You initialize an array with
    Code:
    var variable_name = new Array();
    At this point, you can put just about anything into it and reference it by either key or index
    Code:
    variable_name[0];
    variable_name[1][1];
    variable_name["key"];
    variable_name["key"][2]; // Not quite sure about this format, but the index should work
    for(var i = 0; i < variable_name.length; i++) {
      x = variable_name[i]; alert(x[0] + " is " + x[1]);
      }
    |||||
    o . Q
    ___ "You live and you learn; or you don't live long." - Lazarus Long

    ^_^

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles