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
Value | Type | Explanation |
---|---|---|
value | Required | Specifies the value to be searched in an array. |
start | Optional | Specifies the starting position. If start is omitted, the default value is -1. |
Return Values
Value | Explanation |
---|---|
Number | The last index at which a given element can be found in the array. |
-1 | If 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.