How js uses dynamic keys to deconstruct objects
This article mainly introduces js how to use dynamic keys for object deconstruction, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor with you to understand.
Object deconstruction using dynamic keys
We know that when an object is deconstructed, you can use: to rename the deconstructed property. However, did you know that when the key name is dynamic, you can also deconstruct the properties of the object?
Const person = {id: 1, name: 'front-end name'}; const {name: personName} = person;console.log (personName); / / 'front-end small intelligence'
Now, we use dynamic keys to deconstruct attributes:
Const templates = {'hello':' Hello there', 'bye':' Good bye'}; const templateName = 'bye';const {[templateName]: template} = templates;console.log (template) / / Good bye Thank you for reading this article carefully. I hope the article "how js uses dynamic keys to deconstruct objects" shared by the editor will be helpful to you. At the same time, I hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!