Div*_*ham 2 javascript arrays string flatten
我想做这样的事情:
[1,[2],[3,4]] + " is a Nested Array."
=> "[1,[2],[3,4]] is a Nested Array."
但是,
console.log([1,[2],[3,4]] + " is a Nested Array.");
给出1,2,3,4 is a Nested Array.
我可以通过在字符串中添加方括号并使数组变平来实现单维数组:
"["+ [1,2,3,4,5] + "] is a single dimensional array."
=> "[1,2,3,4,5] is a single dimensional array."
Run Code Online (Sandbox Code Playgroud)
console.log(JSON.stringify([1,[2],[3,4]]) + " is a Nested Array.");Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
74 次 |
| 最近记录: |