Snippets
Reusable code snippets for Python, JavaScript, HTML, CSS, SQL, and more. Copy and use in your projects.
Array Destructuring
Unpack array values into named variables in one line — swap values, skip items, and grab the rest.
const [first, second, ...rest] = [1, 2, 3, 4, 5]
// first=1, second=2, rest=[3,4,5]
// swap variables without a temp
[a, b] = [b, a]es6destructuringarrays 78
Open pagePromise.all Parallel Fetch
Fire multiple async requests in parallel and wait for all of them — dramatically faster than sequential awaits.
const urls = ["/api/a", "/api/b", "/api/c"]
const results = await Promise.all(
urls.map((u) => fetch(u).then((r) => r.json()))
)
// results = [dataA, dataB, dataC]promiseasyncfetch 58
Open pagelocalStorage Helper
Typed wrapper around localStorage that auto-parses JSON and silently catches quota / private-mode errors.
const store = {
get(key, fallback = null) {
try { return JSON.parse(localStorage.getItem(key)) ?? fallback }
catch { return fallback }
},
set(key, val) {
try { localStorage.setItem(key, JSON.stringify(val)) } catch {}
},
}localStoragestoragejson 40
Open page