Modern JavaScript (ES6+) for Beginners
Lesson 5 of 12 42% of course

Destructuring — Arrays & Objects

1 · 5 min · 6/7/2026

Learn Destructuring — Arrays & Objects in our free Modern JavaScript (ES6+) for Beginners series. Step-by-step explanations, examples, and interview tips on Toolliyo Academy.

Sign in to track progress and bookmarks.

Destructuring — Arrays & Objects
Lesson 5 of 12 · Part 2 — Write Less Code · Modern JavaScript (ES6+) for Beginners
Course: Modern JavaScript (ES6+) for Beginners · Lesson: 5/12 · Read time: ~18 min · Level: Beginner · ES version: ES2015 (ES6) and above

Destructuring — Arrays & Objects

Destructuring pulls values out of arrays or objects into variables in one line. React props, API responses, and function parameters all use this pattern: const { name, email } = user.

Array destructuring

const colors = ['red', 'green', 'blue'];
const [first, second] = colors;
// first = 'red', second = 'green'

const [, , third] = colors;  // skip first two
// third = 'blue'

const [head, ...rest] = colors;
// head = 'red', rest = ['green', 'blue']

Object destructuring

const user = { id: 42, name: 'Alex', email: 'alex@toolliyo.com', role: 'student' };

const { name, email } = user;
const { role: userRole } = user;  // rename to userRole

// Default if missing
const { phone = 'N/A' } = user;
🌍 Real-world example — API user profile (React / Node)
async function showProfile(response) {
  const data = await response.json();
  const { name, email, plan = 'free' } = data.user;

  return `${name} (${email}) — ${plan} plan`;
}

// Simulated API object:
showProfile({
  json: async () => ({ user: { name: 'Ravi', email: 'ravi@example.com' } })
});

Destructuring in function parameters

function printOrder({ orderId, items, total }) {
  console.log(`Order #${orderId}: ${items.length} items, ₹${total}`);
}

printOrder({ orderId: 'A100', items: [1, 2], total: 1498 });
⚠️ Common Mistake: Destructuring undefined: const { x } = null throws. Use defaults: const { x } = obj || {} or optional chaining (Lesson 12 preview).
💡 Tip: In React: function Card({ title, children }) { } — that is object destructuring of props.
👨‍🏫 Teaching note: Pass a nested API JSON on screen; students write destructuring for user.name and address.city.

Continue learning

Previous: Template Literals & Modern Strings

Next: Spread & Rest Operators (...)

Course home: All 12 lessons

Test your knowledge

Quizzes linked to this course—pass to earn certificates.

Browse all quizzes
Modern JavaScript (ES6+) for Beginners

On this page

Array destructuring Object destructuring Destructuring in function parameters Continue learning
Part 1 — Modern Basics
Introduction — Why ES6+ Before Node.js & React let, const & Block Scope Arrow Functions Explained
Part 2 — Write Less Code
Template Literals & Modern Strings Destructuring — Arrays & Objects Spread & Rest Operators (...)
Part 3 — Data & Collections
Default Parameters & Object Shorthand Array Methods — map, filter, find & reduce for...of, Sets & Maps Essentials
Part 4 — Async & Modules
Promises — then, catch & finally async/await & Fetch API Modules — import/export & What to Learn Next
Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details