I need to build an array of paths based on the current directory back to a predefined top level directory.
In Javascript have two variables ‘topLevelDirectory’ and ‘currentDirectory’
I need an array of all paths in between.
example :
topLevelDirectory = "/sectionA/sectionB"
currentDirectory = "/sectionA/sectionB/sectionC/sectionD/sectionE
“
I need an array ‘allPaths’ that would have the values:
allPaths[0] = '/sectionA/sectionB/'
allPaths[1] = '/sectionA/sectionB/sectionC/'
allPaths[2] = '/sectionA/sectionB/sectionC/sectionD/'
allPaths[3] = '/sectionA/sectionB/sectionC/sectionD/sectionE/'
I am using Jquery.
I know I can split currentDirectory but then I am not getting the value I need,
‘sectionC’ instead of ‘/sectionA/sectionB/sectionC/’
I am not expecting the full code to the answer, just some help in what functions or procedures I should be trying to tie together.
Any help is appreciated.
This isn’t very elegant or terribly robust, but it seems to work for your example…
Here’s a demo: http://jsfiddle.net/QrCBn/