[] .concat([" x"," y"]," z") - >如何获得[[" x"," y"]," z"]而不是[" x"," y& #34;" Z"]?

时间:2015-07-03 13:08:02

标签: javascript arrays immutability

这很奇怪,但我找不到任何简单的解决方案。

注意:我使用不变性,所以我绝对不想修改原始数组(不建议使用push

[].concat(["x","y"],"z") - >如何获取[["x","y"],"z"]而不是["x","y","z"]

1 个答案:

答案 0 :(得分:8)

您可以使用嵌套数组:

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

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