easierbycode
12/1/2015 - 8:46 PM

https://plus.google.com/photos/photo/115133653231679625609/6223348535793445234

cats = ['', '', ''];

// access the first 3 items of array
cat1 = cats[0];
cat2 = cats[1];
cat3 = cats[2];

// destructure the array (ES2015)
var [c1, c2, c3] = cats;
console.log( c1, c2, c3 );

//<-   



// omit certain values
var [gatoUno, , gatoTrès] = cats;
console.log( gatoUno, gatoTrès )

//<-  



// destructure an array using the rest operator (ES2015)
var [kitty, ...otherKitties] = cats;
console.log( kitty, otherKitties );

//<-  ["", ""]



// destructure an object (ES2015)
catAges = { Itchy:5, Scratchy:7, Pvssy:18 };
var { Scratchy, Pvssy } = catAges;
console.log( Scratchy, Pvssy )
//<- 7 18



// default values for function params
req = ({ url: url = "github.com", crossDomain: crossDomain = true }, ...data) => {
  console.log(`url: ${url}, crossDomain: ${crossDomain}, data: ${data}`);
};

req({ url: "cutepvssies.com" }, "pretty", "kitties" );
//<- url: cutepvssies.com, crossDomain: true, data: pretty,kitties