Skip to content

Tag: nested

Accessing nested arrays with dynamic depth via indices

I’m fairly new to typescript and I have some issues to access an object in array with dynamic depth. For example: To get Folder4 I’d use the dot notation like: this.folder[0].children[0].children[1] Now I was wondering, if there is a way to dynamicly access the object via the position array without iterating over the whole structure. I managed to get it

Convert array of flat objects to nested objects

I have the following array (that’s actually coming from a backend service): where Item is: In order to be compatible with a component that displays a tree (folder like) view, it needs to be transformed into: where NestedItem is: All I’ve tried so far is something like: But this only gets the first level of children, of course (direct children