<script>
function getArray(data,name){
for (var i in data) {
console.log('i',i);
console.log('data'+i,data[i].children);
if (data[i].name == name) {
console.log(data[i]);
break;
} else {
getArray(data[i].children, name);
}
}
}
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);
}
</script>
原文链接:https://blog.csdn.net/yf275908654/article/details/52215321
网友评论