What is indexOf in javascript?

 Array indexOf method javascript:


indexOf() method find position index that element available. if we will define the Second parameter then it's the return start position. And if we will not find the given value then it will return -1.

Syntax of indexOf method:



indexOf example in javascript:


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



// 0


console.log(colors.indexOf('Red', 1));

// start from index 1

// expected output: 3



// expected output: -1

No comments:

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

Copyright Reserved to Anything Learn. Powered by Blogger.