I have an array of paths:
const paths = [
"/path/to/first",
"/path/to/second",
"/path/to/third",
"/path/from/first",
"/path/from/second",
"/users/bill",
"/users/john"
];
I'd like to convert this to a javascript object of this form:
{
path: {
to: {
first,
second,
third
},
from: {
first,
second
}
},
users: {
bill,
john
}
}
How would I do this using pure javascript (not jQuery, and not using JSON.parse or other shortcuts).
If necessary, the end points can be key:value pairs that point to "null" for example:
user: {
bill: null,
john: null
}
I'm hoping for a non-recursive solution, but if this is significantly simpler with recursion, then that's ok!