0
var a = {
  b: {
    ab: {
      abc: 1
    }
  }
}

console.log(a.b.ab.abc)

The output will be 1.

Is it in any way possible to determine the parents of 'a.b.ab.abc' without previously knowing them?

In otherwords, given a.b.ab.abc could one determine the a or a.b or a.b.ab?

  • So, do you mean that you've been given `a.b.ab.abc` and you want `a` as result? – 31piy Jan 02 '18 at 16:52
  • 1
    Your question is unclear. What do you mean by `to determine the parents` and by `without knowing them`? – Igor Soloydenko Jan 02 '18 at 16:52
  • If you have object property `a.b.ab.abc`, then you already know that `a`exists, `b` exists,`ab` exists, etc. Do you want to know if `a` has a "parent"? – Sébastien Jan 02 '18 at 16:54
  • Please refer to the definition of the word "question" @IgorSoloydenko in a dictionary, i think you have it wrong. –  Jan 02 '18 at 16:57
  • "You can't. There is no upwards relationship in JavaScript." from the link posted by @Christian had the answer. This is a shame as is quite limiting. –  Jan 02 '18 at 16:58
  • @John yeah, sure https://i.stack.imgur.com/b0tRl.png – Igor Soloydenko Jan 02 '18 at 16:59
  • That is a title not a question (◔_◔) –  Jan 02 '18 at 17:00
  • You can look up the parent if you know the property you're looking for - or I should say key. – zfrisch Jan 02 '18 at 17:00
  • Yea i was actually playing around with a state management lib. and it would be extremely helpful to be able to know the path to the parent from a leaf of an object. Thought someone might know if there was something in the pipeline for any of the new javascript tricks coming out in the future. –  Jan 02 '18 at 17:03

0 Answers0