Lasso Soft Inc. > Home

[ map->get ]

Method

[map->get] returns value associated to a key from the map. Accepts a single parameter which is the key of the key/value pair of the map element.

This method is similar to the [map->find] method, but it is more strict in that if the map does not contain a key then [map->get] throws an error while [map->find] would just return [void]

Note: This method does not work in the same way as the similarly named [map->get] tag of previous versions of Lasso™

  • Syntax
map->get(map_key)
Examples
  • Beginner

To get each of the values of a map:

Use the [map->get] method.  The following code loops through the map displaying each value.

Code

var (colours = map( 'red'='#ff0000', 
    'green'='#00ff00', 
    'blue'='#0000ff') )

 with i in $colours->keys 
     do => {^
          $colours->get(#i)+'\n'
     ^}

Result

#0000ff
#00ff00
#ff0000

Calling the method with an unknown key

If you pass a value to [map->get] that is not a key in the map, then a failure will be raised.

Code

var(my_map) = map('moose'='yuk', 'elk'='yum', 'croc'='chicken')

$my_map->get('goose')

Result

-9956 The key was not found

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