0

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

null
    • Sean
    • 5 yrs ago
    • Reported - view

    It might be an array, but the only funtions I could get to work with my test array are item() and slice().

    • JCSchell
    • 5 yrs ago
    • Reported - view

    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.

    • Sean
    • 5 yrs ago
    • Reported - view

    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.

    • SvenSteffen_Arndt
    • 1 yr ago
    • Reported - view
    • Nicholas_Doherty
    • 3 mths ago
    • Reported - view
    • Kim_Schacht
    • 3 mths ago
    • Reported - view

    Let f := x + y

    f

    • Alain_Fontaine
    • 3 mths ago
    • Reported - view

    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])
    • Sean
    • 3 mths ago
    • Reported - view
     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

  • 3 mths agoLast active
  • 8Replies
  • 3329Views
  • 5 Following