I have an array of strings in Javascript that look like this:
var array = [{
string: 'path1/path2/path3'
}, {
string: 'path1/path4/path5'
}, {
string: 'path1/path2/path6'
}, {
string: 'path10/path7'
}, {
string: 'path10/path8/path9'
}];
My goal is to create a data model with the following structure:
-- path1
-- path2
-- path3
-- path6
-- path4
-- path5
-- path10
-- path7
-- path8
-- path9
Any suggestions on how I can achieve this? Thank you!
Edit:
I was considering something like:
var paths = {
children: [
{
name: "path1",
children: [
{
name: "path2",
children: [
{
name: "path3",
children: []
}]
},
{
name: "path4",
children: [
{
name: "path5",
children: []
}]
}
}
],
.......
};