I work on a project with a lot of arrays and in some case I have this:
(我在一个有很多数组的项目上工作,在某些情况下,我有这个问题:)
let main_array = [a,b,c,d,[e,f,g],h,i,j,[k,l,m,o],[p],q,[]]
In my main array I have a lot of subarrays, and I want to get all element from them without removing the other elements from the main array.
(在我的主数组中,我有很多子数组,我想从中获取所有元素,而又不从主数组中删除其他元素。)
So I want a function which can do this: (所以我想要一个可以做到这一点的函数:)
f(main_array) --> [a,b,c,d,e,f,g,h,i,j,k,l,m,o,p,q]
The particularity with the main array is about the number of arrays inside it, in fact, it could have 0 to n subarray(s) with 0 to n element(s).
(主数组的特殊性是关于其内部数组的数量,实际上,它可以具有0到n个子数组以及0到n个元素。)
Is there an existing built-in function or just a simple function with filter for example that can solve this problem in a few line of code (just 1 could be great !) ?
(是否存在现有的内置函数或仅带有过滤器的简单函数,例如,可以在几行代码中解决此问题(仅1个就可以了!)?)
PS: I use node.js
(PS:我使用node.js)
ask by bosskay972 translate from so