SitePoint Sponsor

User Tag List

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

    get an object's position in an array?

    how does one go about checking what an object's positon is (numerically) in an array?

  2. #2
    Currently Occupied; Till Sunda Andrew-J2000's Avatar
    Join Date
    Aug 2001
    Location
    London
    Posts
    2,475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:

    <script type="text/javascript">

    obj_in_array '7';

    var 
    num = new Array()
    num[0] = '1';
    num[1] = '2';
    num[2] = '3';
    num[3] = '4';
    num[4] = '5';
    num[5] = '6';
    num[6] = '7';

    document.write('total in arrayis equal to ' num.length);

    for (
    a=0,b=num.length;a<=b;a++)
    {
    if (
    num[a] == obj_in_arrayalert(a)
    }

    // or the opposite way round

    for (a=0,b=num.length;a<=b;a++)
    {
    if (
    obj_in_array == num[a]) alert(num[a])
    }

    </script> 
    hope that helps
    Last edited by Andrew-J2000; May 1, 2002 at 15:00.

  3. #3
    SitePoint Zealot
    Join Date
    Feb 2002
    Posts
    123
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    that should do the trick. thank you very much.

  4. #4
    Currently Occupied; Till Sunda Andrew-J2000's Avatar
    Join Date
    Aug 2001
    Location
    London
    Posts
    2,475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    np...


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
  •