Overview
Learn how to access properties using selectors.
The bracket notation is another way to access properties in CQL, and it is particularly useful when the property name is not a valid identifier or when you want to use selectors.
Unlike the dot notation, the bracket notation supports any property name, including those that are not a valid identifier.
The syntax consists of the variable name followed by a selector enclosed in square brackets ([ and ]):
subject[/*<selector>*/]
Here is a basic example that accesses the interests property of the user variable:
user['interests']
You can also use numeric indexes to access items from a list:
user.interests[0]
Although this notation supports arbitrary property names and selectors, it may still not be the best choice for all scenarios.
Consider using the bracket notation when:
- The property name is not a valid identifier or is not known in advance.
- You need to access items from a list using numeric indexes.
- You want to leverage the power of selectors.
- Anyone reading the queries is familiar with this notation.
- You prefer to stick to a single notation throughout your queries.