Question 6
Back to Exercise
What does the following JavaScript code print (console output, as in Node.js)?
const steps = ["start", "finish"];
const removed = steps.splice(1, 0, "build", "test");
console.log(removed, steps);
- A [ 'finish' ] [ 'start', 'build', 'test' ]
- B [] [ 'start', 'build', 'test', 'finish' ] Correct
- C [] [ 'build', 'test', 'start', 'finish' ]
- D undefined [ 'start', 'build', 'test', 'finish' ]
Correct Answer: Option B
A delete count of 0 removes nothing (so splice returns an empty array) and inserts the new items at 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!