如题我想获取menu数组下的带http开头的路径,最后还是为空?怎么回事?
var menu = [{
"path":"/a",
"children":[{"path":"http://baidu.com","children":[]},
{"path":"/a1","children":[]},
{"path":"/a2","children":[]}]},
{"path":"/b","children":[{"path":"/b1","children":[]}]},
{"path":"/c","children":[],}]
function exPath(arr) {
var path = '';
arr.some((item)=>{
if(item.path.match(/^http/g)) {
path = item.path
return;
} else {
if(item.children.length) {
exPath(item.children)
}
}
})
return path;
}
var t = exPath(menu);
console.log(t)
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
我的 path 的 path 不是我的 path
path 是个局部变量 你下面
返回就对上面没效果了