File tree Expand file tree Collapse file tree 1 file changed +4
-5
lines changed Expand file tree Collapse file tree 1 file changed +4
-5
lines changed Original file line number Diff line number Diff line change @@ -34,12 +34,11 @@ export default {
34
34
const node = {id: crypto .randomUUID (), label: key, children: []};
35
35
if (Array .isArray (value)) {
36
36
// if value is an array of objects, make each key its index
37
+ const containsObjects = typeof value[0 ] === ' object' ;
37
38
value .forEach ((subValue , index ) => {
38
- if (typeof value[0 ] === ' object' ) {
39
- createNodeList (` index ${ index} ` , subValue || {}, node .children );
40
- } else {
41
- createNodeList (subValue, value[subValue] || {}, node .children );
42
- }
39
+ const key = containsObjects ? ` index ${ index} ` : subValue;
40
+ const obj = containsObjects ? subValue : value[subValue];
41
+ createNodeList (key, obj || {}, node .children );
43
42
});
44
43
} else if (typeof value === ' object' ) {
45
44
Object .keys (value).forEach (subKey => {
You can’t perform that action at this time.
0 commit comments