1

I want to pass a multidimensional array to a custom function. I do it like this:

=customFunction({{"a1v1"; "a1v2"};{"a2v1"; "a2v2"; "a2v3"};{"a3v1"}})

However, I don't get the expected behavior because it behaves like a 1-dimension array.

2

You're not adding an array or string but an object. Objects are not processed as such and simply returned. Coincidentally, you discovered that a semi-colon creates a column presentation and a backslash a row presentation.

If you really want to add an array notation as a parameter, then you need to do the following.

Formula

=customFunction("[['a1v1', 'a1v2'],['a2v1', 'a2v2', 'a2v3'],['a3v1']]")

Code

function customFunction(multiArray) {
  return  eval(multiArray);  
}

Screenshot

enter image description here

Explained

Prepare the string with single and double quotes, in order to use text within the array. This string is then evaluated, via the eval() method, as it if were JavaScript.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.