You can use Array.flatMap() to iterate the objects, and then iterate the attributes with Array.map(), and combine with the rest of the object. The Array.flatMap() would also flatten the array of arrays to a single array.
With Ramda, you can iterate and flatten the array using R.chain. To get an array of attributes combined with their parents, you can use the R.ap as combinator of two functions:
Extracts the attributes array, and then applies it to the 2nd function.
Gets the rest of the object (without the attributes), and creates a mapping function that merges it to the iterated objects.
发布评论
评论(4)
您可以使用
array.flatmap()
迭代对象,然后使用属性
使用array.map()
,然后与其余对象。array.flatmap()
还将将数组的数组变为一个数组。使用RAMDA,您可以使用
r.chain
迭代和平坦数组。要获得一系列属性与父母相结合,您可以将r.ap
作为两个函数组合器:You can use
Array.flatMap()
to iterate the objects, and then iterate theattributes
withArray.map()
, and combine with the rest of the object. TheArray.flatMap()
would also flatten the array of arrays to a single array.With Ramda, you can iterate and flatten the array using
R.chain
. To get an array of attributes combined with their parents, you can use theR.ap
as combinator of two functions:您可以使用 /code> and 数组#flat 如下:
或仅名称
属性
,如果还有其他属性:You can use
Array#map
andArray#flat
as follows:Or to only name
attributes
, in case there are other properties:此代码应该对您有用:
This code should work for you:
在我的情况下,我的数组是在对象中有对象,那里有子阵列。我想要一个带有所有子对象的单个数组,
因此我使用此功能将所有对象在单个数组中获取
这是我的代码
结果:
In my case my array is having objects with in objects there are child array. I wanted a single array with all child objects
So I used this function to get all objects in a single array
here is my code
results :