Javascript - Object Destructuring
Code Life
By Pierre Marsaa
Unpacking an Object
Imagine you have an object representing a Codémon and you want to store several of its properties in variables. Normally, you would read them one by one:
↗️
Loading editor...
↶
↷
Just like with arrays, destructuring lets you unpack those properties in a single line. Since objects use keys instead of positions, you write the key names inside curly braces {} on the left of =:
↗️
Loading editor...
↶
↷
You only list the properties you need — here type is simply ignored.
Verify