Wednesday, December 22, 2021
The lastIndexOf() method searches for last appearance the element in the array that matches the passed in value. In this example we will search for the value 60.50 in the array. The lastIndexOf() method takes two arguments. The first argument is the value to search for, the second argument is optional and specifies the index to start the search at. If the second argument is omitted the search will start at the first element of the array.
Here is the output:
As you can see the first lastIndexOf() method call returns the index of 4 because that's where 60.50 resides. It was able to find the element because the second argument was omitted therefore the search starts at the end of the array and returns the first index that it finds from the end. The second lastIndexOf() method call has the value of 1 as the second argument that tells the method start the search at index 2 in the array because that's the new end of the array according to the method.
<script> var oilPrices = [70.15, 69.50, 71.23, 74.32, 69.50, 76.99]; var searchAtBeginning = oilPrices.lastIndexOf(60.50); var searchAtIndex = oilPrices.lastIndexOf(60.50,2); console.log("searchAtBeginning: " + searchAtBeginning); console.log("searchAtIndex: " + searchAtIndex); </script>
Here is the output:
As you can see the first lastIndexOf() method call returns the index of 4 because that's where 60.50 resides. It was able to find the element because the second argument was omitted therefore the search starts at the end of the array and returns the first index that it finds from the end. The second lastIndexOf() method call has the value of 1 as the second argument that tells the method start the search at index 2 in the array because that's the new end of the array according to the method.
Subscribe to:
Post Comments (Atom)
Search This Blog
Tags
Web Development
Linux
Javascript
DATA
CentOS
ASPNET
SQL Server
Cloud Computing
ASP.NET Core
ASP.NET MVC
SQL
Virtualization
AWS
Database
ADO.NET
AngularJS
C#
CSS
EC2
Iaas
System Administrator
Azure
Computer Programming
JQuery
Coding
ASP.NET MVC 5
Entity Framework Core
Web Design
Infrastructure
Networking
Visual Studio
Errors
T-SQL
Ubuntu
Stored Procedures
ACME Bank
Bootstrap
Computer Networking
Entity Framework
Load Balancer
MongoDB
NoSQL
Node.js
Oracle
VirtualBox
Container
Docker
Fedora
Java
Source Control
git
ExpressJS
MySQL
NuGet
Blogger
Blogging
Bower.js
Data Science
JSON
JavaEE
Web Api
DBMS
DevOps
HTML5
MVC
SPA
Storage
github
AJAX
Big Data
Design Pattern
Eclipse IDE
Elastic IP
GIMP
Graphics Design
Heroku
Linux Mint
Postman
R
SSL
Security
Visual Studio Code
ASP.NET MVC 4
CLI
Linux Commands
Powershell
Python
Server
Software Development
Subnets
Telerik
VPC
Windows Server 2016
angular-seed
font-awesome
log4net
servlets
tomcat
AWS CloudWatch
Active Directory
Angular
Blockchain
Collections
Compatibility
Cryptocurrency
DIgital Life
DNS
Downloads
Google Blogger
Google Chrome
Google Fonts
Hadoop
IAM
KnockoutJS
LINQ
Linux Performance
Logging
Mobile-First
Open Source
Prototype
R Programming
Responsive
Route 53
S3
SELinux
Software
Unix
View
Web Forms
WildFly
XML
cshtml
githu
Thanks I will use these tips!
ReplyDelete