I have this code :
foreach (Object element in elements.under)
{
...
}
and I'd like to print some only when I'm into the last cycle. How can I do it?
1) Using the array length property The length property returns the number of elements in an array. Subtracting 1 from the length of an array gives the index of the last element of an array using which the last element can be accessed.
JavaScript Array forEach()The forEach() method calls a function for each element in an array. The forEach() method is not executed for empty elements.
foreach (Object element in elements.under)
{
if (element == elements.under.Last())
{
//Print Code
}
else
{
//Do other thing here
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With