LearnFrenzy
Sign in Take a free test

Spread and Rest Operators · Spread and Rest MCQ · Question 12

Spreading an object into an array Answer, explanation & discussion

  • MCQ
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 12 Back to Exercise

What does [...{ a: 1, b: 2 }] do?

  • A Returns [1, 2]
  • B Throws a TypeError: object is not iterable Correct
  • C Returns ["a", "b"]
  • D Returns [{ a: 1, b: 2 }]
Correct Answer: Option B

Array spread uses the iteration protocol. Use Object.values(obj) or Object.keys(obj) first.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links