在数组内映射数组

Tom*_*dos 0 javascript

我正在尝试将所有项目映射到一个数组中:

[
  [
    { id: 0, name: 'New Project', apiKey: '.'},
    { id: 1, name: 'New Project', apiKey: '.}
  ],[
    { id: 3, name: 'New Project', apiKey: '.'},
    { id: 4, name: 'New Project', apiKey: '.}
  ]
]
Run Code Online (Sandbox Code Playgroud)

全部在一个数组中(输出):

[
 { id: 0, name: 'New Project', apiKey: '.'},
 { id: 1, name: 'New Project', apiKey: '.},
 { id: 3, name: 'New Project', apiKey: '.'},
 { id: 4, name: 'New Project', apiKey: '.}
]
Run Code Online (Sandbox Code Playgroud)

我试过了,var result = allUserProjects.map(user => {user.map(project => project)}) 但这没有任何改变

Nic*_*ies 7

const arr = [
  [
    { id: 0, name: 'New Project', apiKey: '.'},
    { id: 1, name: 'New Project', apiKey: '.'}
  ],[
    { id: 3, name: 'New Project', apiKey: '.'},
    { id: 4, name: 'New Project', apiKey: '.'}
  ]
];

const output = arr.flat();
console.log(output)
Run Code Online (Sandbox Code Playgroud)

您可以使用Array.flat()https : //developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flat