SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    Feb 2002
    Posts
    123
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    getting an array's index?

    hey, i have an array that i'm trying to figure the index out of when i have the value figured out already:
    PHP Code:
    var rinksIDsArray = new Array();
    rinksIDsArray[0] = 5
    rinksIDsArray
    [1] = 
    for example, i know that the value going into my function is going to be '5'.

    how can i pull out the appropriate index from the rinksIDsArray?

    thanks for any help you can give!

    grant

  2. #2
    morphine for a wooden leg randem's Avatar
    Join Date
    Jun 2002
    Location
    .chicago.il.us
    Posts
    957
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    function array_pos(val,arr){
      for(var i=0;i<arr.length;i++){
        if(arr[i]==num) return i;
      }
      return -1;
    }
    alert( array_pos(5,rinksIDsArray) );
    ----Adopt-a-Sig----
    Your message here!

  3. #3
    SitePoint Zealot
    Join Date
    Feb 2002
    Posts
    123
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ahhh, thanks so much. i'l give it a shot


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
  •