Lasso Soft Inc. > Home

[ array->get ]

Method

[array->get] returns an item from the array.

Accepts a single integer parameter identifying the position of the item to be returned.

The first element in an array is at position 1.

This method can be used as the left parameter of an assignment operator to set an element of the array.

An error will be returned if an item is requested which is greater than the size of the array.

  • Syntax
array->get(array_position)

array->get(array_position) = new_value
Examples
  • Beginner
  • Intermediate

To return an element from an array:

Use the array->get method to return an item from an array with a particular index.

The following example returns the second item from an array of the days of the week.

Code

var(DaysOfWeek = array('Sun','Mon','Tue','Wed','Thu','Fri','Sat'))
//display the second element
$DaysOfWeek->get(2)

Result

Mon

To set an element of an array

Use the array->get method as the left parameter of an assignment to update the value of an element of an array.

The following example adds 1 to every other element of an array. 

Code

var( myNumbers = array(1,2,3,4,5,6))
//original array
$myNumbers

loop($myNumbers->size) => {
     loop_count % 2 == 0 ? $myNumbers->get(loop_count) += 1
}

//updated array
$myNumbers

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