Hi dear welcome to "CodePrime" Blog . In this post you are going to learn JavaScript Array Methods - indexOf & lastIndexOf Finction | Javascript Tutorial: 28 | . First Creat A index.html file Copy This HTML CODE and pest it one your code editor. 2ndly creat indexof-and-lastindexof.js file Then Copy The JS CODE and pest it then open the index.html file with your browser.
HTML CODE
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="/index-and-lastindex.js"></script>
<title>javascript</title>
</head>
<body >
<br><br>
<h2>Javascript Tutorial <br>By Codeprime</h2>
</body>
<style>
h2{
color:#fff;
background-color: #000;
padding: 5px;
}
</style>
</html>
JAVASCRIPT CODE
//indexof - example
document.write("<h2> IndexOf - example </h2> <br>")
var a = ["Hanif", "Rubia","Hassan","Rubia"];
document.write(a + "<br><br>")
var b = a.indexOf("Rubia", 2);
document.write(b + "<br><br>")
//lastindexof - example
document.write("<h2> LastIndexOf - example </h2> <br>")
var c = a.lastIndexOf("Rubia", 2);
document.write(c + "<br><br>");
0 Comments