xxxxxxxxxx
const url = 'www.samanthaming.com/tidbit.jpg';
// 1. Split string by "."
const array = url.split('.'); // [ 'www', 'samanthaming', 'com/tidbit', 'jpg' ]
// 2. Create only the variable we want
const [ , domain, ,type] = array;
// 3. Consuming the variable we created
const name = `${domain}.${type}`;
// 'samanthaming.jpg'
xxxxxxxxxx
// ❌ Ugh, useless variable assignment
const [ignore, keep] = ['ignore', 'keep'];
// ✅ Good (blank space)
const [, keep] = ['ignore', 'keep'];
// ✅ Good ("_" communicates useless variable)
const [_ignore, keep] = ['ignore', 'keep'];
xxxxxxxxxx
let [
chili,
, // rotten
, // rancid
apple,
olive,
] = ['chili', 'rotten', 'rancid', 'apple', 'olive'];
// OR
let [
chili,
/* rotten */,
/* rancid */,
keep,
olive
] = ['chili', 'rotten', 'rancid', 'keep', 'olive'];