How to append values to an array
How do you append a value to an array? The closest I get is:
var x := ["Hi", "there"];
var y := ["dude"];
x+y
but, while it dosen't have an error in it's code, it does not return an array
8 replies
-
It might be an array, but the only funtions I could get to work with my test array are item() and slice().
-
There is turning the array to text with concat() appending it and then making it back into an array with split() but it’s cumbersome.
-
let myArray1 := [1, 2, 3];
let myArray2 := [4, 5, 6];
let myArray3 := myArray1 + myArray2;
let myArray4 := [item(myArray3, 0), item(myArray3, 1), item(myArray3, 2), item(myArray3, 3), item(myArray3, 4), item(myArray3, 5)];
alert(text(last(myArray4)))All the Ninox functions worked doing this and myArray4 could probably be initialized using a loop. Still, kind of cumbersome. I tried using concat() on myArray3 and all I got back was a single string of 123456.
-
maybe this helps?: https://docs.ninox.com/en/script/functions/array
-
This should answer your question:
https://forum.ninox.com/t/p8y31x3/how-to-iteratively-add-items-to-a-new-array
-
Let f := x + y
f
-
The only known way, as far as I know, to add something to an array, and get an *array* as the result, is to use the "array()" function. The function takes two arrays as arguments, and returns their concatenation as a new array. To add a single element, of the same type as those already in the array, one must first convert this element into a single element array:
newArray := array(oldArray, [addedElement])
-
said:
The only known way, as far as I know, to add something to an array, and get an *array* as the result, is to use the "array()" function.posted a solution nearly 5 years ago in this thread - Universal array handling when array items are not text strings. I posted an example database in this thread - Numeric array variable initialization that expands on his solution to add inserting, deleting and replacing elements in an array.
Content aside
- 11 mths agoLast active
- 8Replies
- 3574Views
-
5
Following