我正在寻找一种将这个递归对象数组转换为扁平化对象数组以便更容易处理的方法。
每个
我可以使用
[
{
"name": "bill",
"car": "jaguar",
"age": 30,
"profiles": [
{
"name": "stacey",
"car": "lambo",
"age": 23,
"profiles": [
{
"name": "martin",
"car": "lexus",
"age": 34,
"profiles": []
}
]
}
]
}
]
这是预期的输出。
[
{
"name": "bill",
"car": "jaguar",
"age": 30,
},{
"name": "stacey",
"car": "lambo",
"age": 23,
},{
"name": "martin",
"car": "lexus",
"age": 34,
}
]
每个
profiles
数组可以有n
个项目,这些项目可能有一个空的子profiles
数组,也可能没有。注意转换后的数组对象不包含profiles
。我可以使用
underscore
或lodash
来实现这一点。