Displaying array elements in order

Discussion in 'Ruby' started by Pragash Mr., Jul 15, 2008.

  1. Pragash Mr.

    Pragash Mr. Guest

    Hi,

    for example


    a=[12,354,633,68,85]
    <%for i in a%>
    <%z=Document.find(i)%>
    <%=z.name%>
    <%end%>

    Here the result is displaying randomly in browser
    but i want to display the result in the array order
    i.e first 12 then followed by 354,633,68,85

    If you have any solution plz reply
    --
    Posted via http://www.ruby-forum.com/.
    Pragash Mr., Jul 15, 2008
    #1
    1. Advertising

  2. On Jul 15, 2008, at 11:28, Pragash Mr. wrote:

    > a=3D[12,354,633,68,85]
    > <%for i in a%>
    > <%z=3DDocument.find(i)%>
    > <%=3Dz.name%>
    > <%end%>
    >
    > Here the result is displaying randomly in browser
    > but i want to display the result in the array order
    > i.e first 12 then followed by 354,633,68,85


    If that's happening, the array is ordered randomly before the `for` =20
    construct. Arrays are inherently ordered, so using a `for` will always =20=

    yield the elements in the order they appear in the array. Try =20
    inspecting the array before looping over it to see which order the =20
    elements are in.

    --=20
    Mikael H=F8ilund
    http://hoilund.org/
    Mikael Høilund, Jul 15, 2008
    #2
    1. Advertising

  3. Pragash Mr.

    Pragash Mr. Guest

    Mikael Høilund wrote:
    > On Jul 15, 2008, at 11:28, Pragash Mr. wrote:
    >
    >> a=[12,354,633,68,85]
    >> <%for i in a%>
    >> <%z=Document.find(i)%>
    >> <%=z.name%>
    >> <%end%>
    >>
    >> Here the result is displaying randomly in browser
    >> but i want to display the result in the array order
    >> i.e first 12 then followed by 354,633,68,85

    >
    > If that's happening, the array is ordered randomly before the `for`
    > construct. Arrays are inherently ordered, so using a `for` will always
    > yield the elements in the order they appear in the array. Try
    > inspecting the array before looping over it to see which order the
    > elements are in.



    Hi,
    Before the for loop also i checked but it is displaying in random order
    even though aray order is [12,354,633,68,85]
    but i have one doubt if it is ajax call then it will display in random
    order... plz reply
    --
    Posted via http://www.ruby-forum.com/.
    Pragash Mr., Jul 15, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Irishmaninusa

    Dropdown displaying data in the wrong order

    Irishmaninusa, Aug 26, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    439
    Irishmaninusa
    Aug 27, 2004
  2. Soren Kuula
    Replies:
    2
    Views:
    488
    Soren Kuula
    Feb 1, 2004
  3. P
    Replies:
    1
    Views:
    1,147
    Joe Kesselman
    Jul 7, 2006
  4. Matt Constantine
    Replies:
    2
    Views:
    86
    Robert Klemme
    Sep 22, 2008
  5. Tuxedo
    Replies:
    8
    Views:
    125
    Tuxedo
    May 7, 2007
Loading...

Share This Page