SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict scoobasteve1982's Avatar
    Join Date
    Apr 2007
    Posts
    333
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    JavaScript ArrayList like Java??

    I was wondering if anyone knew how to make an array in JavaScript without knowing how many elements your array is going to hold? In Java I can use the ArrayList class, but it seems in JavaScript that I need to know how many elements my array is going to have. I'm pull data dynamically so the index will increase greatly over time. I could set the inital value to some huge number, however iterating over the array will take forever. Any ideas? Thanks for your time. NEVERMIND, I found the answer to my question. You simply created the array like so:

    Code:
    var myArray = [];
    and then initialize the values in the array when ready.

  2. #2
    Avid Logophile silver trophy
    ParkinT's Avatar
    Join Date
    May 2006
    Location
    Central Florida
    Posts
    2,329
    Mentioned
    191 Post(s)
    Tagged
    4 Thread(s)
    That's right. And Javascript supports the .push and .pop methods on arrays.
    SWEEEET!

    Off Topic:


    Cool Avatar !
    Don't be yourself. Be someone a little nicer. -Mignon McLaughlin, journalist and author (1913-1983)


    Git is for EVERYONE
    Literally, the best app for readers.
    Make Your P@ssw0rd Secure
    Leveraging SubDomains

  3. #3
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What you created is an Array literal. You can also create arrays using the Array Object constructor.

    Check out Mozilla's excellent reference on arrays.


Bookmarks

Posting Permissions

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