What is lastIndexOf in javascript?

 Array lastIndexOf method javascript:

 

lastIndexOf() method find a position for all defined element but it's count only the last index. And if we will not find the given value it will be returned -1. Also, you can know about indexOf().

Syntax of lastIndexOf method:

array.lastIndexOf()

 

lastIndexOf example in javascript:

 

const colors = ["Red", "blue", "Black", "Red", "Orange", "White"];

 

console.log(colors.lastIndexOf('Red'));

// 3

 

console.log(colors.lastIndexOf('Green'));

// -1

 


No comments:

Note: Only a member of this blog may post a comment.

Copyright Reserved to Anything Learn. Powered by Blogger.