Question 19
Back to Exercise
What does the following JavaScript code print (console output, as in Node.js)?
const arr = ["a", "b"];
console.log(0 in arr, "a" in arr, "length" in arr);
- A false true false
- B true true true
- C true false true Correct
- D false true true
Correct Answer: Option C
in checks keys, not values. Index 0 is a key of the array, "a" is a value, and length is an own property of every array. Use includes() to search values.
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!