Trying to grab a value after using Object.entries

The object below is a result of an expansion of some tree and I have to grab the descriptionPath value and this descriptionPath appears only in the last expanded children as shown below for the Child of Very Small Bank children.

{
	"title": "National Bank",
	"bank_cd": "",
	"description": {
		"name": "Private Bank",
		"key": "\\\\Some Key\\Path\\testing1\\testing2\\testing3"
	},
	"children": [{
		"title": "Small Bank",
		"bank_cd": "",
		"description": {
			"name": "Small Bank",
			"key": "\\\\Some Key\\Path\\testing1\\testing2\\testing3\\Small Bank"
		},
		"children": [{
			"title": "Very Small Bank ",
			"bank_cd": "",
			"description": {
				"name": "Very Small Bank ",
				"key": "\\\\Some Key\\Path\\testing1\\testing2\\testing3\\Small Bank\\Very Small Bank "
			},
			"children": [{
				"title": " Child of Very Small Bank ",
				"bank_cd": "123456",
				"description": {
					"bank_cd": "123456",
					"descriptionPath": "\\A\\B\\V\\D\\text1\\text2\\text3\\text5\\"
				},
				"expanded": true
			}],
			"expanded": true
		}],
		"expanded": true
	}],
	"expanded": false
}

For example, if nothing would have been expanded, it would have looked like :

{
	"title": "National Bank",
	"bank_cd": "",
	"description": {
		"name": "Private Bank",
		"descriptionPath": "\\A\\B\\V\\D\\text1\\text2\\text3\\text5\\"
	},
	
	"expanded": false
}

So, in order to grab the descriptionPath, I was thinking of converting it to array using Object.entries method as shown in the JSFiddle here.

However, in the console.log, I am not seeing descriptionPath anywhere. Am I following wrong approach here?

This is a recursive dive problem.

Consider this:
What is inside of the nodes that you dont want, that is NOT inside of the one you do?

Hmm. I am wondering, why in console log, it’s not showing descriptionPath ?

It’s done exactly what you told it to do. And descriptionPath is in your log.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.