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 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 is used to arrange the array elements in some order. By default, method follows the ascending order. Syntax The method is represented by the following syntax: array.sort(compareFunction) Parameter compareFunction - It is optional. It represents a function that provides an...
1 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 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 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 copyWithin() method The JavaScript array copyWithin() method copies the part of the given array with its own elements and returns the modified array. This method doesn't change the length of the modified array. Syntax The copyWithin() method is represented by the following syntax: array.copyWithin(target, start, end) Parameter target -...
1 min read
JavaScript Array method The JavaScript array 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...
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 Method If you work with JavaScript, you will often find yourself handling arrays and lists of values stored in a single variable. A common need is to combine two or more arrays into one bigger array. That is exactly what the concat() method helps...
7 min read
JavaScript Array method The JavaScript array method is used to add, remove or replace elements to/from the existing array. It returns the removed elements from an array. The method also alters the original array. Syntax: The method is represented by the following syntax: array.splice(start, delete,...
4 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