Get full path (as string) from a JavaScript Object

Viewed 144

Given a JavaScript object:

const websiteTree = { 
    home: {
       about: {},
       categoryA: {
           postA: {}
       }
    }
}

and a path:

websiteTree.home.categoryA.postA

how could I get the nested path as "string", example:

console.log(getUrlPath(websiteTree.categoryA.postA)) // expected output: "/categoryA/postA"

I need a data structure to represent URLs in JavaScript. No idea how I can do this.

0 Answers
Related