例如,如果我有
{
"key1":{
"key2":[
{
"key3":[
{
"key4":{
"key5":0
}
},
{
"key6":{
"key7":""
}
}
]
},
{
"key8":{
"key9":true
}
}
]
}
}
有没有办法获得这样的所有键?
["key1", "key2", "key3", "key4", "key5", "key6", "key7", "key8", "key9"]
编辑:我在这里尝试了suggestion,但它没有成功Typescript: what could be causing this error? "Element implicitly has an 'any' type because type 'Object' has no index signature"
答案 0 :(得分:1)
你需要一个递归函数来迭代。
试试这个
{{1}}