<script>
var arrs = [];
function haha(){
var data = [
{
name: '中国',
children: [
{
name: '教第三节课',
},
{
name: '教呼呼',
children: [
{
name: '大一',
children: [
{
name: '课程1',
children: [
{
name: '1231'
},
{
name: '121'
}
]
},
{
name: '课程2',
children: [
{
name: '1232'
},
{
name: '122'
}
]
},
{
name: '课程3',
children: [
{
name: '1233'
},
{
name: '123'
}
]
},
]
}
]
},
{
name: '活动',
children:null
}
]
}
];
getArray(data,'活动');
console.log(data);
for(var i in undefined){
alert(123);
}
}
function getArray(data,name)
{
for (var i in data) {
console.log('i',i);
console.log('datai',data[i].children);
if (data[i].name == name) {
console.log(data[i]);
break;
} else {
getArray(data[i].children, name);
}
}
}
</script>
JS递归遍历树结构
最新推荐文章于 2024-09-13 23:50:28 发布