Question 6
Back to Exercise
What does the following JavaScript code print (console output, as in Node.js)?
console.log("a-b-c".split("-", 2), "abc".split("-"), "a-b-c".split("-", 0));
- A [ 'a', 'b-c' ] [] []
- B [ 'a', 'b' ] [ 'a', 'b', 'c' ] [ 'a-b-c' ]
- C [ 'a', 'b' ] [ 'abc' ] [ 'a', 'b', 'c' ]
- D [ 'a', 'b' ] [ 'abc' ] [] Correct
Correct Answer: Option D
The limit caps the result; when the separator is not found the whole string is the only piece; a limit of 0 returns an empty array.
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!