【发布时间】:2021-08-21 09:39:48
【问题描述】:
我有这个数据结构:
{
"fieldNodes": [
{
"selectionSet": {
"selections": [
{
"name": {
"value": "id"
}
},
{
"name": {
"value": "phone"
}
},
{
"name": {
"value": "address"
},
"selectionSet": {
"selections": [
{
"name": {
"value": "street"
}
},
{
"name": {
"value": "city"
}
}
]
}
}
]
}
}
]
}
我需要以递归方式遍历 fieldNodes 数组,并创建一个包含其值的字符串数组 (name.value)。
嵌套值将由一个点 ("address.city") 表示。
此示例的结果将是:["id", "phone", "address. street", "address.city"]。
我假设我在 fieldNodes 数组中有一个对象。
有人可以帮我看看 NodeJS 中的代码应该是什么样子吗?
【问题讨论】:
-
我尝试了这个解决方案并且它有效。 stackoverflow.com/questions/54857222/…
标签: javascript node.js arrays recursion