Javascript Soritng Method
JavaScript Sorting Method
Hello guys! Today we are going to see that how to use SORTING METHOD in JavaSrcipt.
This will help you in arranging names in alphabetical order or instead of words you can also write numbers.
This will help you in arranging names in alphabetical order or instead of words you can also write numbers.
So, let's directly jump into it......
First, make two files
1) index.html
2) sorting.js
In index.html,
<html>
<head>
<title>
Soritng With Javascript
</title>
</head>
<body>
<h1 style="text-align:center">JAVASCRIPT sorting METHOD</h1>
<script src="sorting.js"></script>
</body>
</html>
In sorting.js,
//enter names you want in this array variable
var names = ["Anna","Jenny","John","Ball","Cat","Musketeer"];
//sort() is in-built javascript function
var sort = names.sort();
//then print it out
document.write(sort);
Output,
Anna, Ball, Cat, Jenny, John, Musketeer
First, make two files
1) index.html
2) sorting.js
In index.html,
<html>
<head>
<title>
Soritng With Javascript
</title>
</head>
<body>
<h1 style="text-align:center">JAVASCRIPT sorting METHOD</h1>
<script src="sorting.js"></script>
</body>
</html>
In sorting.js,
//enter names you want in this array variable
var names = ["Anna","Jenny","John","Ball","Cat","Musketeer"];
//sort() is in-built javascript function
var sort = names.sort();
//then print it out
document.write(sort);
Output,
Anna, Ball, Cat, Jenny, John, Musketeer
go up buddy
ReplyDeleteThanks Askalon amp; Askarock
ReplyDeleteNice Dharm
ReplyDelete