Get the App
SLTechnology News&Howtos  ›  Development  › 

How js sets dynamic property names in objects

Shulou Source: shulou.com Published: 2022-06-01 06:01:54 11月15日 Update

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!

Tags: Attributes dynamic object name content front end articles tips chocolates learning help just need skills easy to understand more organization knowledge editing industry information Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn MariaDB NVidia Xiaomi Huawei