LearnFrenzy
Sign in Take a free test

Arrays · Predict the Output · Question 15

Array.from a string and a Set Answer, explanation & discussion

  • Output
  • Easy
  • 0 comments
  • Answer explained
  • Moderated community
Question 15 Back to Exercise

What does the following JavaScript code print (console output, as in Node.js)?

main.js
console.log(Array.from("abc"), Array.from(new Set([1, 1, 2])));
  • A [ 'a', 'b', 'c' ] [ 1, 2 ] Correct
  • B [ 'abc' ] [ 1, 1, 2 ]
  • C [ 'a', 'b', 'c' ] [ 1, 1, 2 ]
  • D TypeError
Correct Answer: Option A

Strings iterate by character; a Set has already removed the duplicate 1.

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