Esc6 object part 2
Computed Property Names
With ES6, you can now use computed property names. Using the square bracket notation [], we can use an expression for a property name, including concatenating strings. This can be useful in cases where we want to create certain objects based on user data (e.g. id, email, and so on).
Here are three examples:
Example 1:
Example 2:
Example 3:
It is very useful when you need to create custom objects based on some variables.
Comments
Post a Comment