

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to perform numeric sort in JavaScript?
To perform sorting in JavaScript, use the sort() function. You can try to run the following code sort numeric values.
Example
<!DOCTYPE html> <html> <body> <script> var arr = [75, 20, 90, 9, 49, 32, 69, 66]; document.write("Initial Values: "+arr); function myFunction() { arr.sort(function(val1, val2){return val1 - val2}); document.write("<br>Sorted Values: "+arr); } myFunction(); </script> </body> </html>
- Related Questions & Answers
- How to sort mixed numeric/alphanumeric array in JavaScript
- Sort Array of numeric & alphabetical elements (Natural Sort) JavaScript
- How to perform sort using Java?
- How to perform Merge Sort using C#?
- How to perform ascending order sort in MongoDB?
- How to perform descending order sort in MongoDB?
- Perform aggregation sort in MongoDB?
- C++ Program to Perform Stooge Sort
- How to perform custom sort by field value in MySQL?
- How to sort varchar numeric columns by DESC or ASC in MySQL?
- C++ Program to Perform the Shaker Sort
- Perform Bubble Sort on strings in Java
- 8085 Program to perform selection sort in ascending order
- 8085 Program to perform selection sort in descending order
- 8085 Program to perform bubble sort in ascending order
Advertisements