0

I'm not sure if there is a specific name for this way to pull object properties into their own variable? If there is a name, does anyone know?

var object = {
  something: 'a string',
  another: 'another string',
}
var { something, another } = object;
Jacob
  • 72,750
  • 22
  • 137
  • 214
Dan
  • 464
  • 4
  • 16
  • 1
    [object destructuring](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment) – PSL Aug 31 '16 at 00:31
  • Ahh, thanks. Wanted to know so I can check if I can use it an older version of node. – Dan Aug 31 '16 at 00:34
  • The newer versions of node do support this @Dan – James111 Sep 04 '16 at 00:04
  • @James111 Yeah, I saw that [v6+](http://node.green/#destructuring--declarations) supports it. Thanks – Dan Sep 04 '16 at 01:06

2 Answers2

1

This is called object destructuring.

Fissure King
  • 1,205
  • 7
  • 17
0

Object destructuring, read up on it here:

https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment

A lot of this new syntax isn't fully implemented in all js engines, so be careful when using it!

If you want to learn more about it, checkout this tutorial:

https://www.eventbrite.com/engineering/learning-es6-destructuring/

James111
  • 12,551
  • 13
  • 64
  • 104