Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialLauren Clark
33,155 Pointsconst [a,b,c] = someArrayIteration[i] What is declaring a variable this way called?
In the React tutorial, there is a for loop which iterates over the winning combinations for Tic-Tac-Toe
It goes like this:
function calculateWinner(squares){
const lines = [
[0, 1, 2],
[3, 4, 5],
[6, 7, 8],
[0, 3, 6],
[1, 4, 7],
[2, 5, 8],
[0, 4, 8],
[2, 4, 6],
];
for (let i = 0; i < lines.length; i = i+1) {
const [a, b, c] = lines[i];
console.log(c);
if (squares[a] && squares[a] === squares[b] && squares[a] === squares[c]) {
return squares[a];
}
}
return null;
}
Now there is a constant variable declared there as "const [a,b,c] = lines[i]"
I can see that this is like declaring 3 variables at once and passing in the current items from the two-dimensional array, which I've never come across before - what is this called? And does anyone have any other examples of it in the wild?