Image

Javascript Program to Sort an Array

Sort an array in ascending order without using an inbuilt function.


  1. let arr = [5,9,3,7,8,100];  
  2.   
  3. for (let i = 0; i < arr.length; i++) {  
  4.   for (let j = i + 1; j < arr.length; j++) {  
  5.     if (arr[i] > arr[j]) {  
  6.       temp = arr[i];  
  7.       arr[i] = arr[j];  
  8.       arr[j] = temp;  
  9.     }  
  10.   }  
  11. }  
  12. console.log(`Result of sorted array is ${arr}`);  
  13. "Result of sorted array is 3,5,7,8,9,100"  

Categories: Java Script Tags: #ES6, #JavaScript,

Newsletter Subcribe

Receive updates and latest news direct from our team. Simply enter your email.