0

I need to safely get a reference to an object like this:

var length = Obj1.Obj2.Obj3.Obj4.Length;

I know I can use bunch of if conditions or ternary operators, to get null when either of Obj1..4 are null.

Is there a cleaner way in TS or JS to safely handle nulls?

In C#, I can use something like Obj1?.Obj2?.Obj3?.Obj4?.Length but I wonder how to do similar in TS or JS

Allan Xu
  • 7,998
  • 11
  • 51
  • 122

0 Answers0