Nested Destructuring
Destructure arbitrarily deep structures in one assignment. Guard against undefined with default empty objects/arrays.
Destructure arbitrarily deep structures in one assignment. Guard against undefined with default empty objects/arrays.
const { a: { b: { c } } } = { a: { b: { c: 42 } } };
// c = 42
// Safe nested with defaults
const { data: { user: { name = "anon" } = {} } = {} } = response;
// Mixed array + object
const [{ id, title }, ...others] = articles;
Deep destructuring is powerful but can hurt readability — consider intermediate variables for clarity.
More in JavaScript