Lasso Soft Inc. > Home

[ array ]

Type

An array is an object that can hold multiple values which are referenced by an index position. An array can be thought of as a series of numbered variables or as a list. Array elements are indexed from 1 and are always sequential. Arrays can hold values of any other data type. Arrays can hold integers, decimals, strings, pairs, or even other arrays or maps. The size of an array is only limited by the amount of memory that is available.

An array is a random access container. Elements can be quickly accessed by providing the position of the element to retrieve. The first element of an array is at position one. Zero is an invalid position within an array.

Arrays are dynamically sized. Inserting an element into an array will cause the array to grow by one. Removing an element will shrink the array by one.

Arrays provide quick insertion at the end (constant time), but inserting an element at any other position will result in all subsequent elements being shifted down (making the operation O(n)). Because of this, if insertions at the beginning are required, an array might not be the best choice of container (a [list] might perform better).

  • Syntax
  • Methods
  • Traits
array(element_1, element_2, ..., element_n)
Has methods:
Examples
  • Beginner

To create an array of the days of the week:

Use the [array] type with each of the names of the days of the week as parameters. The following example stores an array with the names of the days of the week in a variable named daysOfTheWeek. We then retrieve an element from the variable using its index.

Code

local(daysOfTheWeek) = array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday')
daysOfTheWeek->get(2)

Result

Monday

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 2014 | Web Development by Treefrog Inc | PrivacyLegal terms and Shipping | Contact LassoSoft