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.


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.


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


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


enter image description here


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.