0

change single items of an array

Hi,

i would like to know how i change single items of an array.

Let's say if have an array := [a,b,c] and i want to change item 2 [b] to f. The final array will look like [a,f,c].

How can i do that?

 

Kind regards

 

Christoph

6 replies

null
    • JCSchell
    • 6 yrs ago
    • Reported - view

    Maybe...

    // are comments 

    var p := 2; //Position to change
    var t := "f"; //change it To
    var x := ["a", "b", "c", "d", "e"]; //data
    var a := slice(x, 0, p);//data before position
    var b := slice(x, p, p + 1);//the position data for clarity
    var c := slice(x, p + 1, cnt(x));//data after the position
    x := split(concat(a) + ", " + t + ", " + concat(c), ", ");//put it back together and make it an array — watch the spaces with the commas

    • Christoph
    • 6 yrs ago
    • Reported - view

    Hallo JCSchell,

    thanks for your response. I was aware of this kind of  a workaround. But it is waaaay to complicated and needs to much effort for such an easy operation. There must be an easier way. Something similar like:

    item (array,3) := f

    Kind regards

    • JCSchell
    • 6 yrs ago
    • Reported - view

    Agreed

    • Christoph
    • 6 yrs ago
    • Reported - view

    But is there an easier way? @NinoxTeam

    • Sean
    • 6 yrs ago
    • Reported - view

    let myArray := ["a", "b", "c"];
    myArray := [item(myArray, 0), "f", item(myArray, 2)];
    alert(text(myArray))

     

    It's not great, but it does preserve the values you don't want to change.

    • Christoph
    • 6 yrs ago
    • Reported - view

    that's not perfect but should do the job. thx :)

Content aside

  • 6 yrs agoLast active
  • 6Replies
  • 2155Views