Skip to content

Commit b527def

Browse files
committed
Move boolean check outside of loop.
1 parent d82204d commit b527def

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

components/CredentialDetailsTree.vue

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,11 @@ export default {
3434
const node = {id: crypto.randomUUID(), label: key, children: []};
3535
if(Array.isArray(value)) {
3636
// if value is an array of objects, make each key its index
37+
const containsObjects = typeof value[0] === 'object';
3738
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);
4342
});
4443
} else if(typeof value === 'object') {
4544
Object.keys(value).forEach(subKey => {

0 commit comments

Comments
 (0)