4

Team,

Where can I find documentation regarding the left side of the equation of the below JavaScript Code:

var [a, b, c] = "10-11-12".split('-');

Result:
a = 10
b = 11
c = 12
// Note: this is used in Google Apps Script

Apps Script UI Example

Thanks!

2
  • 1
    That is no JavaScript, at least in 1.6 and under. Run it in a browser: SyntaxError: Unexpected token [. Nothing like making a language act like others. Yikes. Commented Nov 22, 2012 at 3:44
  • 6
    Why is this getting voted down? This is valid in JavaScript 1.7. Commented Nov 22, 2012 at 3:45

2 Answers 2

10

This is called destructuring assignment

NOTE it's only available if your runtime is >= JavaScript 1.7

Sign up to request clarification or add additional context in comments.

2 Comments

@ChristopherMartin, that's not what the question is, though. The OP is simply looking for documentation regarding this new feature; OP said nothing about implementing/using it.
Just thought it was worth mentioning.
1

Mozilla Developer Network has some great documentation on the split method: https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/String/split

7 Comments

He's asking about the destructing assignment, not the .split() method.
@macek Where does he state that?
@TFerrell, I suppose I'm making an assumption based on the amount of help/documentation you'd get searching for "javascript split method"...
it is implied by him tagging variables declaration
@ChrisO'Kelly - With no offense implied or intended for propjk007, who used the right tags here, I'll eat my hat if the day ever comes that we can depend on everybody to tag their questions correctly. (But yes, I too assumed the question was about the assignment syntax, since .split() is pretty easy to Google.)
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.