ECMAScript 6’s parameter destructuring and forEach()
This blog post gives a brief introduction to destructuring in ECMAScript 6 and how the array method forEach() profits from it. Destructuring ECMAScript 6 allows you to destructure : the target of an assigment can be a pattern that allows you to look into the source of the assignment and assign to variables what you find there. The following is an example of destructuring used in a variable declaration: > let { first: f, last: l } = { first: 'Jane', last: 'Doe' }; > f 'Jane' > l 'Doe' Another example: you can swap the values of two variables x and y like this: [x,y] = [y,x]; Destructuring also works for parameters. The following function has two kinds of parameters: the first parameter is positional (identified by position), the remaining parameters are named (identified by name) and wrapped in a so-called options object (which is actually a second positional parameter). function foo(positional, { named1, named2 ...