How to concatenate two arrays into one in Server Actions? (NodeJS)

Yes.

You can either create a specific custom formatter as suggested by patrick being the most elegant solution for Wappler.

exports.concat = function(arr1, arr2) {
  if (!Array.isArray(arr1)) arr1 = [arr1];
  if (!Array.isArray(arr2)) arr2 = [arr2];
  return arr1.concat(arr2);
}

Or you can go with the RunJS custom module which will achieve exactly the same by running custom JS but implies running an additional step. With the formatter you can just chain the function where you need it.

Both solutions are more performant than the workaround you found out.

1 Like