Tech Study

JavaScript String indexOf() Method

JavaScript String indexOf() Method

The indexOf javascript () method returns the position of the first occurrence of an element of a string or arrays. This method returns -1 if the value is not found or NULL. It is a case-sensitive method.

SYNTAX – string.indexOf(searchValue, start)

Where,

The string represents the given string to be checked on.

searchValue – required value to search for

start – The position from where to start. It is an optional field. If start<0, the search starts from the back of the string i.e. start+string length is used.

The method returns the first position where the value exists. It returns -1 if the value never occurs. The method compares the search Value with elements of the array or string using strict equality. In arrays, if the slots are empty, it skips them.

indexOf() is an ESI feature and it is supported by all browsers.

For Example –

const arr = [1,4,5,6,7];

arr.indexOf(1); // 0

arr.indexOf(8); // -1

arr.indexOf(6,1); // 3

Java Final keyword

Introduction : java final keyword The final keyword present in Java programming language is generally used for restricting the user. …

Read more

C++ Memory Management: new and delete

C++ Memory Management We know that arrays store contiguous and the same type of memory blocks, so memory is allocated …

Read more