JavaScript Array lastIndexOf() method17 Mar 2025 | 1 min read The JavaScript array lastIndexOf() method is used to search the position of a particular element in a given array. It behaves similar to indexOf() method with a difference that it start searching an element from the last position of an array. The lastIndexOf() method is case-sensitive. The index position of first character in a string is always start with zero. If an element is not present in a string, it returns -1. SyntaxThe lastIndexOf() method is represented by the following syntax: Parameterelement - It represent the element to be searched. index - It represent the index position from where search starts. It is optional. ReturnAn index of a particular element. JavaScript Array lastIndexOf() method exampleLet's see some examples of lastIndexof() method. Example 1Here, we will print the position of an element. Test it NowOutput: 3 Example 2In this example, we will provide the index value from where the search starts. Test it NowOutput: 1 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 JavaScript array method is used to invoke the specified function once for each array element. Syntax The method is represented by the following syntax: array.forEach(callback(currentvalue,index,arr),thisArg) Parameter callback - It represents the function that test the condition. currentvalue - The current element of array. index - It...
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
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 method creates and returns a new array from different a number of arguments. It does not focus on the type and number of arguments. Similar to Array, it also provides a constructor that handles the integer arguments, but in a...
2 min read
JavaScript Array method The JavaScript array method removes the last element from the given array and return that element. This method changes the length of the original array. Syntax The method is represented by the following syntax: array. Return The last element of given array. JavaScript Array method...
1 min read
JavaScript Array Method The method creates a new iterator object of an array, holding the key/value pairs for every value in the array. A key represents the index number carrying an item as its value. It does not affect the original array. Syntax The following syntax...
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 calls the specified function for every array element and returns the new array. This method doesn't change the original array. Syntax The method is represented by the following syntax: array.map(callback(currentvalue,index,arr),thisArg) Parameter callback - It represents the function that produces...
1 min read
JavaScript Array Method The method creates a new array iterator object that carries the values specified at each array index. We can iterate the array elements via loops or iterator methods. Syntax array.; Parameter It does not hold any parameter as such. Return It creates and returns a newly created...
2 min read
JavaScript Array Method The method creates a string that represents the elements of an array. It converts the array elements into the string. Syntax array.; Parameter array: It is the given array or the source array. Including this, there are two optional parameters also. locales: It is a string that...
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