0

This is my first post here. I saw a bit of TypeScript code that was a list of objects, something like:

obj1.obj2.obj3[obj1.obj2.obj3.length-1].span

What is the ".span" doing here? I searched the internet and could not find anything.

Thanks in advance

Brandon Buck
  • 7,177
  • 2
  • 30
  • 51
JackSpace
  • 1
  • 2
  • 1
    Just another property name... – CertainPerformance Jun 04 '22 at 04:57
  • 1
    This code is pretty funky, to begin with, which is leading to the confusion. Let's unpack this. The first thing to note is that `.` and `[]` are both "property accessors" in Javascript. So `obj1.obj2.obj3` returns an object, probably an array (since it's accessed with a number, not really but it's easier to explain this way), then they're looking up the last item (can tell by `length - 1`) of this array. And finally they're accessing the `.span` property of the last object in that array. – Brandon Buck Jun 04 '22 at 05:51

0 Answers0