Ads Top

What is indexOf in javascript?

 Array indexOf method javascript:


indexOf() method find position index that element available. if we will define Second parameter then it's start position. And if we will not find given value then it will be 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.