I am using a underscore array iterator to manipulate a object. the result should be need to return as single time, But i am getting multiple time, as like my array length. how to correct this?
here is my function:
var ValidPaths = {
"green":{
"url":"greenController.js",
"lightgreen" :{
"url":"lightGreenController.js",
"floragreen":{
"url":"floragreenController.js",
"ultragreen":{
"url":"floragreenController.js",
}
}
}
}
}
var path = "green",
subPath = 'lightgreen/floragreen';
var paths = [path].concat(subPath.split('/')),
arr = [],prePath=ValidPaths;
function pathFinder (path,i){
if(prePath[path]){
arr.push({"label":path,"url":prePath[path]['url']});
prePath = prePath[path];
} else{
console.log("there is no path like " + path + "in ValidPaths");
}
return arr;
}
var breadCrumb = _.map(paths, function(root,i){
return pathFinder(root,i);
});
console.log("breadCrumb", breadCrumb); // giving me 3 arrays instead 1 how to solve this?