KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Object dot notation vs bracket notation
PRODUCT: 4D | VERSION: 17 | PLATFORM: Mac & Win
Published On: September 25, 2019

There are two ways to access properties on an object: dot notation and bracket notation. Both has its advantages and disadvantages listed below:

Dot Notation:

  • Property can only be alphanumeric (no spaces)

  • Property cannot start with a number

  • OK - obj.prop1, obj.prop_1

  • Not OK - obj.prop 1, obj.$varName


Bracket Notation:
  • Property can be any string or variable

  • Property can start with a number and contain spaces

  • OK - obj["1prop"], obj["prop 1"], obj[$varName]


In summary, dot notation is useful for explicitly accessing a specific attribute directly by its name and is easier to read. Bracket notation removes the restriction of properties starting with numbers, allows space characters to be used, and allows variables which can be useful for looping through an object. Analyze your specific scenario and decide which notation is more fitting for you to use.