JSFiddle - React, Tailwind, and code Playground
HTML
<script src="//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.6.0/underscore-min.js"></script>
JavaScript
var ValidPaths = {
"green":{
"url":"greenController.js",
"lightgreen" :{
"url":"lightGreenController.js",
"floragreen":{
"url":"floragreenController.js"
}
}
}
}
var path = ["green"].concat("lightgreen/floragreen".split('/'));
var finArr = []; //should be [ {"label":"green","url":"greenController.js"}, {"label":"lightgreen","url":"lightGreenController.js"},{"label":"floragreen","url":"floragreenController.js"}]
var label = "";
_.each(path, function(str,key){
label += '["'+str+'"]';
finArr.push({label:label,url:ValidPaths[label].url});
});
console.log(finArr);