Question 8
Back to Exercise
What does the following JavaScript code print (console output, as in Node.js)?
console.log("a1b22c333".match(/\d+/g), "a1b22c333".match(/\d+/)[0], "a1b22c333".match(/\d+/).index);
- A [ '1', '22', '333' ] 1 1 Correct
- B [ '1', '22', '333' ] 333 6
- C [ 1, 22, 333 ] 1 1
- D [ '1' ] 1 0
Correct Answer: Option A
With g, match lists every match as a string. Without g, it returns the first match ("1") with details such as its index (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!