JS: Array.prototype.lastIndexOf

By Xah Lee. Date: . Last updated: .

myArray.lastIndexOf(value)

myArray.lastIndexOf(value, start_index)

Return the index of right-most element that is value. Search starts at the end, or at start_index, from right to left.

Return -1 if not found.

[see JS: Array.prototype.indexOf]

const rr = [2, 3, 5, 6, 3];

console.log ( rr.lastIndexOf ( 3 ) ); // 4
// search starts from right

// start search starts from index 1
console.log ( rr.lastIndexOf ( 3, 1 ) ); // 1

console.log ( rr.lastIndexOf ( 3, 0 ) ); // -1
// not found

Reference

ECMAScript® 2016 Language Specification#sec-array.prototype.lastindexof

Array Search Topic

  1. JS: Array.prototype.indexOf
  2. JS: Array.prototype.lastIndexOf
  3. JS: Array.prototype.find
  4. JS: Array.prototype.findIndex
  5. JS: Array.prototype.includes

JS Array

  1. Understand JS Array
  2. Create Array
  3. Sparse Array
  4. Array-Like Object
  5. Array How-To
  6. Array Object
  7. Array.prototype
Liket it? Put $5 at patreon.

Or, Buy JavaScript in Depth

If you have a question, put $5 at patreon and message me.

Web Dev Tutorials

  1. HTML
  2. Visual CSS
  3. JS in Depth
  4. JS Reference
  5. DOM
  6. SVG
  7. Web Dev Blog