0

I having issues understanding the proper way to convert a string like so tree.descendents[0].descendents to a object that I can manipulate. I was seeing that reduce was the way to go, however I couldn't wrap my head around it. Any suggestions/pointers appreciated.

class TreeNode {
constructor(value) {
    this.value = value;
    this.descendents = [];
}}

As you can see I might be deep within the tree object. I am trying to access it by getting the path to my target then set its value. ideally I convert the path to a object and do: myPath.descendents.push(myNewElement)

  • What type of object should a string like `tree.descendents[0].descendent` be? I feel like there's some context missing. Do you have a an object like `const tree = { descendents: [ . . . ] }`? – CollinD Oct 17 '19 at 21:45
  • Please tells us what reference you are using for "the proper way to convert a string like so `tree.descendents[0].descendents` to a [sic] object". – Heretic Monkey Oct 17 '19 at 21:47
  • I have a tree object that within itself has descendents and those descendents have there own descendents. – David George Smith Oct 17 '19 at 21:50
  • 1
    does this help: https://stackoverflow.com/questions/6393943/convert-javascript-string-in-dot-notation-into-an-object-reference? – georg Oct 17 '19 at 21:52

0 Answers0