tback
tback

Reputation: 11561

Is there a javascript equivalent to unpack sequences like in python?

Is there a javascript equivalent to unpack sequences like in python?

a, b = (1, 2)

Upvotes: 20

Views: 7990

Answers (3)

Antony Hatchkins
Antony Hatchkins

Reputation: 33994

[a, b] = [1, 2]

Update:

Browser compatibility matrix:

  • Firefox: all versions
  • Opera: 9.x only
  • Chrome: 49 and higher
  • MSIE: no
  • EdgeHTML: 14 (Browser version 31, released Feb. 2016)
  • Safari: 7.1 (8 for Safari Mobile)

Upvotes: 19

Alsciende
Alsciende

Reputation: 26971

An object cannot contain a reference to an integer, only its value. So I can't see any way to do what you ask in javascript.

Upvotes: -4

Marcin
Marcin

Reputation: 7994

There isn't. JavaScript doesn't have such syntax sugar.

Upvotes: 8

Related Questions