TutorialGetting Started with MacrosMacro EditorUser InterfaceMenus and ToolbarEditing Macro StatementsExpression EditorMacro DebuggingHow ToUsing variablesFinding and modifying objectsCreating new page contentAsking for user inputStoring persistent dataSorting objectsSample MacrosConceptsExpressionsObjectsPropertiesVariablesData TypesArraysFunctionsLiteralsOperatorsComments |
Last updated on: February 06, 2021
Also available as a single HTML file Onetastic Macro Documentation > Concepts > Arrays ArraysVariables can store a single value or a set of values. Variables that store a set of values are of Array data type. Arrays can store an unbounded amount of <key, value> pairs. The values are always accessed by providing the key (known as index). New elements can be added to arrays by assignment and specifying the a key that doesn't exist in the array: Creating Arrays$Names[0] = "Fred"
$Names[1] = "Kate"
$Names[2] = "Sally"
Arrays can also be created by Array function by simply providing the list of elements: $Names = Array("Fred", "Kate", "Sally")
Here the indices are autmatically assigned as 0, 1, 2 Iterating over Array ElementsValues in the array can be iterated over using ForEach statements ForEach ($Name in $Names)
InsertObject($Outline, "Paragraph", -1).text = $Name
Array keys are of string or numeric types and they don't have to follow any order. Array functionsThere are a several functions that generate and consume arrays. QueryObjects and QueryText functions return arrays of objects. String_Split function splits a given string into an array of strings, while Array_Join function reverses this. Array_Length function will return the number of elements in an array. Using an array as a stack or a queueArray_PopFront and Array_PushBack functions can be used as equivalents of dequeue and enqueue operations on a queue data structure. Similarly Array_PushBack and Array_PopBack functions allow an array to be used as a stack, providing simple push/pop functionality. Finally there is an Array_PushFront function to insert an element at the beginning of an array. Multi-dimensional ArraysArrays can be multi-dimensional if they contain other arrays: $Names = Array(Array("Fred", "Williams"), Array("Kate", "Smith"), Array("Sally", "Jones"))
$SallysLastName = $Names[2][1]
|
ReferenceStatementsForEachIfElseWhileExpressionCommentBreakContinueReturnHierarchy ObjectsNotebookRootNotebookSectionGroupSectionPagePage ObjectsTitleOutlineTableColumnRowCellParagraphTextImageEmbeddedFileTagOther ObjectsDialogBoxFunctionsArray FunctionsColor FunctionsData Store FunctionsDate/Time FunctionsDialog Box FunctionsMacro Execution FunctionsObject FunctionsString Functions |