- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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 sort an array of integers correctly in JavaScript?
To sort an array of integers, use sort() in JavaScript.
Example
Following is the code −
var arrayOfIntegers = [67, 45, 98, 52]; arrayOfIntegers.sort(function (first, second) { return first - second; }); console.log(arrayOfIntegers);
To run the above program, you need to use the following command −
node fileName.js.
Here, my file name is demo310.js.
Output
This will produce the following output −
PS C:\Users\Amit\javascript-code> node demo310.js [ 45, 52, 67, 98 ]
- Related Articles
- How to sort an array of integers correctly JavaScript?
- How to create an array of integers in JavaScript?
- Sort an array according to another array in JavaScript
- How to sort an array in JavaScript?Explain with example?
- Using merge sort to recursive sort an array JavaScript
- Java Program to sort integers in unsorted array
- Inverting signs of integers in an array using JavaScript
- Sort by index of an array in JavaScript
- How to sort date array in JavaScript
- How to sort an array of objects based on the length of a nested array in JavaScript
- Odd even sort in an array - JavaScript
- How to sort an array in C#?
- Take an array of integers and create an array of all the possible permutations in JavaScript
- How to use std::sort to sort an array in C++
- Sort an array to have specific items first in the array - JavaScript

Advertisements