JavaScript Array indexOf() method17 Mar 2025 | 1 min read The JavaScript array indexOf() method is used to search the position of a particular element in a given array. This method is case-sensitive. The index position of first element in an array is always start with zero. If an element is not present in an array, it returns -1. SyntaxThe indexOf() method is represented by the following syntax: Parameterelement - It represent the element to be searched.
ReturnAn index of a particular element. JavaScript Array indexOf() method exampleLet's see some simple examples of indexOf() method. Example 1Here, we will print the position of an element. Test it NowOutput: 1 Example 2In this example, we will provide the index value from where the search starts. Test it NowOutput: 3 Example 3Here, we will search an element which is not present in an array. Test it NowOutput: -1 Next TopicJavaScript Array |
JavaScript Array Method The method creates and returns a new iterator object which holds the key for every index in the array. This method does not affect the original array. Syntax array.; Parameter It does not hold any parameter. Return It returns a new array iterator object. JavaScript Array Example Let's...
2 min read
JavaScript Array Method The method is a combination of flat() and map() methods. This method initially maps each array element through a mapping function, then flatten up the array with depth value as 1. Syntax var newArr=arr.flatMap(function callback(currentValue[ , index[ , array]]) { return element } [ , thisArg]) Parameters callback-...
2 min read
JavaScript Array method The JavaScript array method fills the elements of the given array with the specified static values. This method modifies the original array. It returns undefined, if no element satisfies the condition. Syntax The method is represented by the following syntax: arr.fill(value[, start[, end]]) Parameter value...
1 min read
JavaScript Array method The JavaScript array method changes the sequence of elements of the given array and returns the reverse sequence. In other words, the arrays last element becomes first and the first element becomes the last. This method also made the changes in...
1 min read
JavaScript Array Method The method is used to test whether the value passed is an array. If it finds the passed value is an array, it returns True. Otherwise, it returns False. Syntax Array.isArray(obj_value); Parameter obj_value: It is the value of the object which is passed for determining...
2 min read
JavaScript Array Method The JavaScript array method combines two or more arrays and returns a new string. This method doesn't make any change in the original array. Syntax The method is represented by the following syntax: array.concat(arr1,arr2,....,arrn) Parameter arr1,arr2,....,arrn - It represent the arrays to be combined. Return A new...
1 min read
JavaScript Array Method The method reduces the given array elements into a single value by executing a reducer function. The reducer() function is applied against the accumulator and reduces all the elements from right to left. Syntax array.reduceRight(callback(accumulator,currentValue,currentIndex,array),initialValue) Parameter callback: It is the callback function that executes over...
2 min read
JavaScript Array method The JavaScript array method adds one or more elements in the beginning of the given array and returns the updated array. This method changes the length of the original array. Syntax The method is represented by the following syntax: array. unshift(element1,element2,....,elementn) Parameter element1,element2,....,elementn - The...
1 min read
JavaScript Array method The JavaScript array method returns the first element of the given array that satisfies the provided function condition. Syntax The method is represented by the following syntax: array.find(callback(value,index,arr),thisArg) Parameter callback - It represents the function that executes each element. value - The current element...
1 min read
JavaScript Array Method The method creates a new array that holds the shallow copy from an array or iterable object. When applied to a string, each word gets converted to an array element in the new array. Syntax There is a following possible syntax: Array.from(object,map_fun,thisArg); Parameter object: It is...
2 min read
We request you to subscribe our newsletter for upcoming updates.
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India