Tip - Skip elements with Array Destructuring

javascript
Back

Example

You can use an empty 'placeholder' comma to skip elements when destructuring arrays like below.

const url = "https://github.com/mohandere";
const [protocol, , domain, username] = url.split("/"); // [https:", "", "github.com", "mohandere"]
console.log(username); // "mohandere"

Thanks!

MIT © Mohan Dere.
-