我有这样的输入:
const a = 'lol',
b = ['1','2','3'],
c = 'c';
Run Code Online (Sandbox Code Playgroud)
我想合并它,这样输出就是这个数组:
['lol', '1', '2', '3', 'c']
Run Code Online (Sandbox Code Playgroud)
我试过像这样的传播运算符
const arr = [...a, ...b, ...c]
console.log(arr)
Run Code Online (Sandbox Code Playgroud)
但它安慰
["l", "o", "l", "1", "2", 3, "c"]
如果它是一个数组,则仅使用传播:
const arr = [a, ...b, c];
Run Code Online (Sandbox Code Playgroud)
更动态地,使用.flat:
const arr = [a, ...b, c];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
60 次 |
| 最近记录: |