W3Schools offers a wide range of services and products for beginners and professionals, helping millions of people everyday to learn and master new skills.
Enjoy our free tutorials like millions of other internet users since 1999
Explore our selection of references covering all popular coding languages
Create your own website with W3Schools Spaces - no setup required
Test your skills with different exercises
Test yourself with multiple choice questions
Document your knowledge
Create a free W3Schools Account to Improve Your Learning Experience
Track your learning progress at W3Schools and collect rewards
Become a PLUS user and unlock powerful features (ad-free, hosting, support,..)
Not sure where you want to start? Follow our guided path
With our online code editor, you can edit code and view the result in your browser
Learn the basics of HTML in a fun and engaging video tutorial
We have created a bunch of responsive website templates you can use - for free!
Host your own website, and share it to the world with W3Schools Spaces
Create your own server using Python, PHP, React.js, Node.js, Java, C#, etc.
Large collection of code snippets for HTML, CSS and JavaScript
Build fast and responsive sites using our free W3.CSS framework
Read long term trends of browser usage
Test your typing speed
Use our color picker to find different RGB, HEX and HSL colors.
W3Schools Coding Game! Help the lynx collect pine cones
Join our newsletter and get access to exclusive content every month
Contact us about W3Schools Academy for educational institutions
Contact us about W3Schools Academy for your organization
About sales: [email protected] About errors: [email protected]
Find the last index of "Apple":
More than one apple:
More examples below.
The lastIndexOf() method returns the last index (position) of a specified value.
lastIndexOf()
The lastIndexOf() method returns -1 if the value is not found.
The lastIndexOf() starts at a specified index and searches from right to left (from the given postion to the beginning of the array).
By defalt the search starts at the last element and ends at the first.
Negative start values counts from the last element (but still searches from right to left).
Start the search at position 4:
Start the search at the second last position:
Array Tutorial
Array Const
Basic Array Methods
Array Search Methods
Array Sort Methods
Array Iteration Methods
lastIndexOf() is an ECMAScript5 (ES5) feature.
ES5 (JavaScript 2009) is fully supported in all modern browsers since July 2013: