Results 1 to 3 of 3

Thread: split() - Confused about length of returned array.

  1. #1
    Join Date
    Apr 2008
    Location
    San Diego, CA
    Posts
    352
    Thanks
    57
    Thanked 6 Times in 6 Posts

    Default split() - Confused about length of returned array.

    Code:
    oValue = "test1,test2,test3";
    oValue = oValue.split(",");
    alert(oValue.length); // Alerts "3"
    Shouldn't this alert "2" and not "3", since arrays start at 0? When I use a for loop to iterate through this example, the loop only executes 3 times, not 4.

    What am I missing here?
    Last edited by jlizarraga; 11-26-2008 at 09:23 PM. Reason: realized I'm an idiot

  2. #2
    Join Date
    Apr 2008
    Location
    San Diego, CA
    Posts
    352
    Thanks
    57
    Thanked 6 Times in 6 Posts

    Default

    Just pretend there's a var in front of that first oValue. v_v

  3. #3
    Join Date
    Apr 2008
    Location
    San Diego, CA
    Posts
    352
    Thanks
    57
    Thanked 6 Times in 6 Posts

    Default

    UGH. I don't know why I thought array.length was supposed to give you the highest index.

    I am braindead today. v_v

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
  •