Array lastIndexOf in JavaScript

Level 263 keystrokes

lastIndexOf() returns the last index at which a given element is found.

JavaScript code

// Create an array with duplicate values
1const nums = [1, 2, 3, 2, 1];
// lastIndexOf() finds the last occurrence of 2 (returns 3)
2console.log(nums.lastIndexOf(2));

Output

3
Practice typing this code

Practice typing this code. Results are not recorded in the rankings.

Symbols in this code

The symbols you type in this JavaScript code and how often they appear.

  • ,× 4
  • ;× 2
  • .× 2
  • (× 2
  • )× 2
  • [× 1
  • ]× 1
  • =× 1

More JavaScript examples at level 2

← JavaScript typing practice