[] .concat (["x", "y"], "z") & # 8594; How do I get [["x", "y"], "z"] instead of ["x", "y", "" z "]?

It's weird, but I can't seem to find an easy solution.

Note . I'm using immutability so I absolutely don't want to modify the original array (don't suggest using push

)

[].concat(["x","y"],"z")

→ How to get [["x","y"],"z"]

instead ["x","y","z"]

?

+3


source to share


1 answer


You can use a nested array:



> [].concat([["x", "y"]], "z")

[["x", "y"], "z"]

      

+8


source







All Articles