Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- todots = (child, valProp = 'name', nestedProp = 'children', result = {}, path = 'root') => {
- if (!child) {
- return
- }
- result[path] = child
- if (child[nestedProp]) {
- for (let c of child[nestedProp]) {
- todots(c, valProp, nestedProp, result, path + '.' + child[valProp])
- }
- }
- return result
- }
- obj = {
- name: 'child1',
- children: [
- {
- name: 'child of child'
- },
- {
- name: 'child of child',
- children: [
- {
- name: 'child of child'
- }
- ]
- }
- ]
- }
- console.log(Object.keys(todots(obj, 'name', 'children')))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement