Array indexOf Quiz
Multiple Choice Easy
Question
What does `[10, 20, 30].indexOf(25)` return?
Hint
indexOf returns -1 when the element is not in the array.
Explanation
indexOf returns the first index at which the element is found, or -1 if it is not present. Since 25 is not in [10, 20, 30], the result is -1. This is the standard way to check if an array contains a value (or use includes() for a boolean result).
Related Resources
Related Lessons
- JavaScript Arrays
Learn about indexOf and includes.
Related Reference
- JavaScript Array Reference
Reference for indexOf.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.