Lasso Soft Inc. > Home

[ array->forEachPair ]

Method

Part of the standard trait_keyedForEach. When iterating an array in this manner, the pair's ->first value is the element position, while ->second is the element value.

  • Syntax
array->foreachpair => { expression }
Examples
  • Beginner

Return a list of the elements of an array along with their position

This example iterates through an array of names and outputs the position of the name in the array along with name.

Code

define listMe(p::pair) => {  
    return #p->first+'. '+#p->second
}

var( myNames = array('Tom' , 'Jen' , 'Cam' ))

$myNames->foreachpair => {^  listMe(#1)+'\n' ^}

Result

1. Tom
2. Jen
3. Cam

Recent Comments

No Comments found

Please note that periodically LassoSoft will go through the notes and may incorporate information from them into the documentation. Any submission here gives LassoSoft a non-exclusive license and will be made available in various formats to the Lasso community.

LassoSoft Inc. > Home

 

 

©LassoSoft Inc 2015 | Web Development by Treefrog Inc | PrivacyLegal terms and Shipping | Contact LassoSoft