W3Teacher
  • Explore
    Browse by field
    Artificial Intelligence Accounting & Finance Information Technology
    Show all fields
  • Interview Q&A
    • All Interview Questions
    • Beginner
    • Intermediate
    • Advanced
  • Practice
    • MCQs
    • Quizzes
    • Mock Interviews
  • About
  • Sign in
  • Get Started
  1. Home
  2. JavaScript
  3. Destructuring, Spread & Rest
  4. Question
All 10 Destructuring, Spread & Rest questions
More in Destructuring, Spread & Rest
How do you destructure properties out of an object? What does the spread operator (...) do when used on an array? How do you assign default values while destructuring? How does the rest parameter differ from the spread operator, even though they use the same '...' syntax? How do you use spread to shallow-copy and merge objects? How do you destructure nested objects and arrays in one statement? Why must the rest element be the LAST element in a destructuring pattern? How can you use destructuring to swap two variables without a temporary variable? How do computed property names interact with object destructuring?
Advertisement
JavaScript › Destructuring, Spread & Rest

How do you destructure values out of an array?

Beginner

Answer

Array destructuring pulls values out by position into named variables using square-bracket syntax on the left side of an assignment.
const [first, second] = [10, 20];
console.log(first, second); // 10 20
Real-world example Unpacking a [value, setValue] pair returned by React's useState hook.

Common follow-ups: How do you skip an element while destructuring an array?

Arrays & Array Methods
Next question How do you destructure properties out of an object?
All 10 Destructuring, Spread & Rest questions
W3Teacher

Learn technologies. Ace technical interviews.


    Learn
    • Technologies
    • Tutorials
    • Interview Questions
    • MCQs
    Practice
    • Quizzes
    • Mock Interviews
    • Bookmarks
    • Dashboard
    Get the latest questions & tips

    Fresh interview questions and practice tips, straight to your inbox.

    Company
    • About
    • Contact us
    • Privacy Policy
    • Terms & Conditions

    © 2026 W3Teacher. All rights reserved.