ES6 dynamic key (name) for object & object property assignment

Recently, I’ve picked up Javascript again at my day job writing software using ReactJS and Elixir. It had been a while I hadn’t code javascript professionally since AngularJS 1. Since 2014, there are so many new changes to the JS libraries and communities! I need to catch up.

Today I learned the new way in ES6 to use a dynamic key to access or assign an object property.

ES6 enables developers to create or access an object by dynamic keys or names:

You can think of many ways you can apply this to your coding scenario. How about the case where you might need to create an object with an increasing number in the key name?

Or, when you want to replace an item in an array with a dynamic index 😉

ES6's Object.assign function is used to copy the values of all of the enumerable own properties from one or more source objects to a target object

Read more about it here:



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store