JavaScript Array lastIndexOf() Method

You are Here:

JavaScript Array lastIndexOf() Method

The lastIndexOf() method returns the last index at which a given element can be found in the array, or -1 if it is not present.

Note: The array is searched backwards, starting at start index.

HTML Online Editor
<!DOCTYPE html> <html> <body> <script> var myFruit = ["Apple", "Banana", "Cherry", "Apple"]; document.write("Last Index of Apple is - " +myFruit.lastIndexOf("Apple")); document.write("<br>Last Index of Apple is - " +myFruit.lastIndexOf("Apple", 0)); </script> </body> </html>

Syntax

Array.lastIndexOf(value, start)

Parameter Values

ValueTypeExplanation
valueRequiredSpecifies the value to be searched in an array.
startOptionalSpecifies the starting position.
If start is omitted, the default value is -1.

Return Values

ValueExplanation
NumberThe last index at which a given element can be found in the array.
-1If the specified element not found within an array.

Reminder

Hi Developers, we almost covered 97% of JavaScript Tutorials with examples for quick and easy learning.

We are working to cover every Single Concept in JavaScript.

Please do google search for:

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author