This operation has a similar functionality for both JavaScript arrays and
strings.
Like in most programming languages nexl uses square brackets to resolve elements
subset from array ( or string ).
Let's say we have the following JavaScript array:
fruits = ['Mango', 'Banana', 'Mango', 'Annona', 'Grape'];
The following expression resolves a
["Mango","Annona"] array subset (
counting from zero ):
${fruits[2..3]}
To resolve a single array element use the following expression:
${fruits[3]}
It resolves a
"Annona" string.
You can also mix different ranges and single elements countless times between square
brackets ( spaces are ignored ).
For example:
${fruits[1, 3..4]}
The last expression resolves a
["Banana","Annona","Grape"] array elements
subset.
The
^ and
$ characters can be used to access a first and last
array elements.
For example:
${fruits[^..$]}
The last expression resolves all array elements from the first to the last.
The next feature is negative indexes.
Negative indexes are being counted from the end.
I.e. the
-1 index equals to the index number 3 if an array has 5
elements.
For example the following expression will resolve last two array elements
["Annona","Grape"]:
${fruits[-1..$]}
nexl also allows to use expressions instead of hard coded numbers between
square brackets. It allows to slice arrays/strings dynamically.
For example:
${fruits[1..${myIndex}]}
The
myIndex variable must be of a number type or can has one of the following
two string values '^' or '$' to access first and last indexes.
Also
myIndex variable can be provided as
argument.