How js sets dynamic property names in objects
This article mainly shows you "js how to set the dynamic property name in the object", the content is easy to understand, clear, hope to help you solve the doubt, the following let the editor lead you to study and learn "js how to set the dynamic property name in the object" this article.
The dynamic property name in the object
It is easy to set object properties using dynamic keys. Simply use ['key name'] to add attributes:
Const dynamic = 'flavour';var item = {name:' front-end console.log', [dynamic]: 'chocolate'} console.log (item); / / {name: 'front-end small intelligence', flavour: 'chocolate'}
The same technique can be used to reference object properties using dynamic keys:
Const keyName = 'name';console.log (item [keyName]); / / returns' front-end intelligence'is all the content of the article "how to set dynamic property names in an object by js". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!