umangenius-logo
U Man Genius docs
Scripting tips & tricks

icon picker
Arrays in Ninox

JT
Jacques TUR

Simple Arrays

Manipulating arrays of text or numbers is straightforward:
var myArray := ["a", "b", "d"];

index(myArray, "b");
myArray := array(myArray, ["c"]);

myArray order this;
Sorting can also be performed using order, sort, and unsort for text or number arrays. For more array-related functions, refer to the .

Two-Dimensional Arrays

Ninox does not support two-dimensional arrays directly. Instead, use an array of JSON objects. For example, sorting the array by the second element of the d2 field:
var myArray := [{'d2':["a", "Z"]}, {'d2':["b", "B"]}, {'d2':["c", "C"]}, {'d2':["d", "D"]}];

(myArray order by item('d2', 1));
This code return : [{"d2":["b","B"]},{"d2":["c","C"]},{"d2":["d","D"]},{"d2":["a","Z"]}]

Filtering Arrays

You can filter arrays similarly to the result of a select. For text or number arrays, use this to refer to the value being filtered:
var myArray := ["Jan", "Fred", "Jacques"];
myArray[this like "J"] order this;
For JSON arrays, use the key directly:
var myArray := [
{ 'prénom' : "Jan", nom : "Augustin" },
{ 'prénom' : "Fred", nom : "Baillot" },
{ 'prénom' : "Jacques", nom : "Tur" }
];

myArray[nom like "i"] order 'prénom';
This code returns an array of JSON : [{"prénom":"Fred","nom":"Baillot"}, {"prénom":"Jan","nom":"Augustin }]

Custom Operations on JSON Arrays

For JSON arrays, you can include a code block (in parentheses) to execute custom operations for each iteration. Like for in, the resulting array's type matches the last line of code in the block.
Example: Calculating the length of full names (prénom + nom):
var myArray := [
{ 'prénom' : "Leo", nom : "Martin" },
{ 'prénom' : "Paul", nom : "Garnet" },
{ 'prénom' : "Pierre", nom : "Dur" }
];

var nameLengths := myArray[nom like "a"].(
var fullName := ---{'prénom'} {nom}---;
length(fullName)
);
nameLengths;
This code returns an array of numbers [10, 11] representing the lengths of the full names.

Initialising an Empty Typed Array

In Ninox, the usual trick for creating an empty array that still carries the correct record type is to run a select filtered by where false. The query returns zero records but preserves the type of the array elements.
"Empty Invoice Item array:";
let t := (select 'Invoice Item' where false);
t is now an array whose elements are of the Invoice Item type.
Because it is empty yet typed, it can safely be reused as the starting point of array() operations.
search
Why not just use []?
The literal [] is an untyped array. It often works, but when combined with array() on record collections, Ninox may complain about type inconsistencies. The select … where false pattern avoids this issue entirely.

Creating an Empty Array for Primitive Types (Number, Text, JSON...)

When you need an empty array for scalar values – numbers, text strings, or JSON objects – there is no underlying table to select from. You can still obtain a typed empty array by seeding [] with a dummy element and immediately filtering it out:
"Empty number / text / JSON array:";
let t := [1][false]; "t is now an empty but number typed array";
[1] produces a single‑element numeric array; the [false] filter removes that element, leaving an empty array that retains the number type. Use a text or JSON literal instead of 1 if you need those specific types.

Flattening a Two‑Dimensional Array

Each Invoice contains its own Invoice Items sub‑array. To obtain one single list holding all the items from every invoice, loop through the invoices and concatenate their sub‑arrays.
"Initialize empty array:";
let t := (select 'Invoice Item' where false);

"Iterate over each invoice and add its items:";
for i in Invoices do
t := array(t, i.'Invoice Items')
end;

"Return the flattened list:";
t
How it works
for i in Invoices do … end loops over every Invoice record.
array(t, i.'Invoice Items') concatenates the current value of t with the array of items inside that invoice.
On the first iteration, the items of the first invoice are appended.
On the second iteration, the items of the second invoice are added, and so on.
After the loop finishes, t contains all items from all invoices in a single, flat array.
You can now perform operations like count(t) to know the total number of items, or loop/filter over t directly.
Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
CtrlP
) instead.