I have a question for experts :) I'm trying to make a dynamically generated "decision tree". The data you need is stored in a global variable.
const mainObj = { second: { name: 'second', valueToOutput: "someString", }, third: { name: 'third', valueToOutput: "someString", }, first: { name: 'first', nextEls: [second, third] } } When I initialize a variable, I immediately grab the Uncaught ReferenceError: second is not defined error Uncaught ReferenceError: second is not defined , I try to initiate through this
const mainObj = { second: { name: 'second', valueToOutput: "someString", }, third: { name: 'third', valueToOutput: "someString", }, first: { name: 'first', nextEls: [this.second, this.third] } } variable is initiated. But I get such an object at the end
first: { name: 'first', nextEls: [undefined, undefined] }
this is the essence of the problem - is it possible to refer to properties in properties? And if so, how is this better implemented?