C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
JavaScript TypedArray lastIndexOf() MethodThe JavaScript lastIndex()of method returns the last position of a value, or it returns -1 if the value is not found. NOTE: The string is searched from the end to the beginning, but returns the index starting from the beginning, at position 0.The lastIndexof() method is case sensitive. Syntax:array.lastIndexOf(value, start) Parameters:Value: The first parameter is value that is going to be searched in the array. Start: It refers the position where to start the search. If the value is not given in the argument, the default value is the length of the array. Return value:Representing the index of the element where the value is found for the last time, or -1 if the value cannot be found. Browser Support:
ExampleJavaScript lastIndexOf() Method <script type="text/javascript"> // JavaScript to illustrate lastIndexOf() method function JavaTpoint() { // string var str = 'JavaTpoint'; //Finding the index of the string var index = str.lastIndexOf('T'); document.write(index); } JavaTpoint(); // expected output: arr[Output:4] </script> Output: 4 Example 2JavaScript lastIndexOf() Method <script type="text/javascript"> // JavaScript to illustrate lastIndexOf() method function JavaTpoint() { // string var str = 'JavaTpoint'; //Finding the index of the string var index = str.lastIndexOf('s'); document.write(index); } JavaTpoint(); // expected output: arr[Output:-1] </script> Output: -1
Next TopicJavaScript TypedArray Object
|