Languages
[Edit]
EN

JavaScript - convert file paths to tree (multi-level arrays)

4 points
Created by:
Lani-Skinner
748

In this short article, we would like to show how to convert file paths to tree in JavaScript.

Conversion concept:

File paths to tree conversion using JavaScript.
File paths to tree conversion using JavaScript.

Practical example:

Notes:

  • ¥ and  were used because of possible Japanese and Korean path separators,
  • in practise web browsers' APIs work on slashes only, so it is not needed to use ¥ and  separators.

 

for..of based example

Edit

Warning: this solution should be used only with iterable collections.

 

See also

Edit
  1. JavaScript - convert file paths to tree (multi-level maps)

Alternative titles

  1. JavaScript - build files tree from path list (multi-level arrays)
  2. JavaScript - build files tree using file paths (multi-level arrays)
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join