Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

javascript destructing

/*
* On the left-hand side, you decide which values to unpack from the right-hand
* side source variable.
* 
* This was introduced in ES6
*/
const x = [1, 2, 3, 4, 5]
const [a, b] = x
console.log(a) // prints out: 1
console.log(b) // prints out: 2
Source by developer.mozilla.org #
 
PREVIOUS NEXT
Tagged: #javascript #destructing
ADD COMMENT
Topic
Name
2+5 =