Get the App
SLTechnology News&Howtos  ›  Development  › 

How js uses dynamic keys to deconstruct objects

Shulou Source: shulou.com Published: 2022-06-01 06:01:45 10月13日 Update

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!

Tags: Dynamic object article attribute front end intelligence value interest at the same time more friends knowledge editing industry information information channel channel reference learning help Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker Huawei Shulou Information MySQL vpn