首页 > Web开发 > 详细

JSON 多层对象获取键值

时间:2019-11-23 14:55:46      阅读:213      评论:0      收藏:0      [点我收藏+]
<html>
<script>
window.onload = function(){
var 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"){
num ++
trans(data[i])
}
}
}

trans(json)

console.log({arr})

}
</script>
</html>

  

JSON 多层对象获取键值

原文:https://www.cnblogs.com/winyh/p/11917953.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!