Question 7
Back to Exercise
The code below stops with an uncaught error. Which statement correctly describes the problem?
const users = [{ name: "Asha", active: true }, { name: "Ravi", active: false }];
const active = users.filter("active");
console.log(active);
- A It prints [ { name: 'Asha', active: true } ]
- B It prints []
- C It prints both users
- D TypeError: "active" is not a function – filter needs a callback: users.filter((u) => u.active) Correct
Correct Answer: Option D
Array methods do not accept property names (unlike some libraries such as lodash). Pass a function that reads the property.
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!