Product SiteDocumentation Site

5.3. Array lookup

If the dynamic function call is unary and the left-hand-side is an array, the semantics applied is that of array lookup and is as follows.
The unique parameter is cast to an integer $i (an error is raised according to the semantics of casting if this fails).
If $i is comprised between 1 and jdm:size($a), then $a($i) returns the value of the pair at position $i, i.e., jdm:value($a, $i).
Otherwise (i.e., if $i is an invalid position), an empty sequence is returned.
Example 5.3. Array lookup
Query:
        let $wd := ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
        return $wd(1)
Result:
        Sunday
For the following queries, assume the variable $f is bound to the following two dimensional array.
Data:
        [
          [ "mercury", "venus", "earth", "mars" ],
          [ "monday", "tuesday", "wednesday", "thursday" ]
        ]
Query:
        $f(1)
Result:
        [ "mercury", "venus", "earth", "mars" ]
Query:
        $f(2)(2)
Result:
        tuesday