What is findindex in javascript?

 Array findindex method javascript:


findIndex() method returns first value index position When satisfied condition true from the given function as callback. If not find give value then the position will be return -1.

Also, you can read about LastIndexOf().

Syntax of findIndex method:



findindex example in javascript:


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


const getColor = colors.findIndex(element => element == "White");


// 5


const getColorNot = colors.findIndex(element => element == "Green");


// -1

No comments:

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

Copyright Reserved to Anything Learn. Powered by Blogger.