JS object navigation - when to use the object and the object ["sub"]?

Considering this from a point of semantics, there are two ways to navigate objects in JS, you can either use the point operator or work through them as a nested array.

When is it appropriate to use one operator over another? Why don't I just use the method with square brackets all the time (it seems more powerful)? Both of them seem easy to read, but the dot operator looks like it is limited in that it cannot be provided with variable names of nested objects or work with arrays.

+5
source share
1 answer

The main reasons for using []

  • ( , < ES5)
  • ,

.

  • [] , ..
  • [' ( ).

, Chat['users']['getList']()['sort']()['each'].

: ., , [], .

+5

All Articles