Skip to main content

Array functions

In some scripts, you need to store arrays in variables. For example, data from Google Sheets is stored in arrays.

You can use functions when working with arrays.

Underscore functions

Underscore is a JavaScript library. You can use its functions to get and transform data in arrays when configuring your Aimylogic chatbots.

tip
Use the underscore character _ to access the desired functions.

Internal Aimylogic functions

Also, Aimylogic has its own functions which you can use to work with arrays: next, prev, first, current, random.

All functions are invoked directly from the array variable. For example, if you have an $items variable, you can invoke the next function like that: $items.next().

FunctionDescription
nextIterates over array elements and returns the next consecutive element. Returns undefined if either the array is empty or the end of the array is reached. To use next one more time within the session, you should invoke the first function and only after that invoke next.
firstReturns the first element from the array. If the array is empty, returns undefined.
prevInverse to next. Returns the previous element from the array. Returns undefined if either the array is empty or you have not invoked the next or random function within the session.
randomReturns a random element of the array. Returns undefined if the array is empty.
currentReturns the current element of the array. The current function can be invoked only after you have invoked any of the first, next, prev, or random functions. Otherwise, returns undefined.