Is there a way to add an item to the middle of an array?

Just wondering if there's any way to insert into an array– not at the beginning or end, or to define a specific item within it. I've found that Set Variable does not accept things like Array[7], and haven't come across anything about this in the writing on arrays. General suggestions if you have any please!

First, just to be clear, KM does NOT support arrays like other languages. All KM Variables are just plain text. KM does support pseudo arrays by using comma delimited text. But the support is very limited.

You can get one of the pseudo array elements using and index, like
MyVarName[3]
but only in a numeric or calculation field.

See Variable Arrays.

There is no easy way to set a pseudo array element.

I'm not sure what your objective is, but I'd recommend using JavaScript for Automation (JXA) to perform any serious array manipulation. JavaScript has very powerful array methods.

You would use an KM Execute a JavaScript For Automation action.

I'll stop here for now. If you want to provide more details about your objective and whether or not you want to consider using JXA, let us know and we'll try to help more.

2 Likes

Thank you Michael!

1 Like