Practice
JavaScriptData StructuresReactConcepts
Sign in
← Back to problems

Find Position

Fundamentals: Part 2easy

Course · Section 3: JavaScript Fundamentals – Part 2 · Lecture 41: Basic Array Operations (Methods)

Implement `findPosition(arr, value)` returning the index of `value`, or `-1` if absent.

Sample tests

Input: findPosition([10,20,30], 20)
Output: 1
Input: findPosition([1,2], 5)
Output: -1

+ 1 hidden test run on Submit.

Hints

Common pitfalls
  • includes returns a boolean, not the index.
Visualize this concept: Truthy and Falsy Values →
Approach & explanation (try first)

indexOf reports the first index of the value or -1 when missing.

Loading...
⌘/Ctrl + Enter

Run your code to see results.