each_with_index desired column output

Hi,

<% source.strains.each_with_index do |strain, j| %>
<% if (j == (source.strains.size - 1)) %>
Strain <%= strain[0].appendix %>

<% end %>
<% end %>

I need to get output as

If j value is last one of a loop, then i need to print first value of loop (j[0]). Kindly suggest me or correct above script.

Do you realise you are doing nothing at all with all the other members
of the array? If that is what you want then why bother to iterate
through the array, just display element 0.

Not related to your question but it is better to use css rather than
inline font tags.

Colin

Dear Collin,

Hi,

Do you realise you are doing nothing at all with all the other members

of the array? If that is what you want then why bother to iterate

through the array, just display element 0.
Thank you for your point out.

Not related to your question but it is better to use css rather than

inline font tags.
Its working with “source.strains[0].appendix”. Thank you for helping out to find the issue.

Don't forget to check for the case where the array is empty (so
strains[0] will be nil) unless it is impossible for the array to be
empty.

Colin

Dear Collin

Don’t forget to check for the case where the array is empty (so

strains[0] will be nil) unless it is impossible for the array to be

empty.
Ya… I got it. Loads of Thanks once again.