Multilayer JSON object gets key

<html>
<script>
window.onload = function(){
was JSON = {
"options":{
"name":{
"first":{
"some":{
"age":20
}
}
}
},
"checks":{
"nums":{
"done":{
"word":"nice"
}
}
}
}

let arr = []
function trans(data){
let num = 0
for(var i in data){
console.log(i)
let item = {
title:i,
children:[]
}

arr.push(item)
if(typeof data[i] == "object"){
a ++
trans(data[i])
}
}
}

trans(json)

console.log({arr})

}
</script>
</html>

  

Guess you like

Origin www.cnblogs.com/winyh/p/11917953.html