Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

how to sort array least to greatest javascript stACK

function sortArray(array) {
  var temp = 0;
  for (var i = 0; i < array.length; i++) {
    for (var j = i; j < array.length; j++) {
      if (array[j] < array[i]) {
        temp = array[j];
        array[j] = array[i];
        array[i] = temp;
      }
    }
  }
  return array;
}

console.log(sortArray([3,1,2]));
Comment

PREVIOUS NEXT
Code Example
Javascript :: javaScript setFullYear() Method 
Javascript :: destructuring an object js 
Javascript :: dot geometru three js 
Javascript :: js object from array of keys 
Javascript :: like in mongodb 
Javascript :: how to check if local storage is available 
Javascript :: console.log() Print Values Stored in Variables 
Javascript :: jquery validate on keyup 
Javascript :: Search array of objects for existing value 
Javascript :: includes in js 
Javascript :: jquery add 
Javascript :: how to create a class javascript 
Javascript :: modulus js 
Javascript :: how to get variable from url in javascript 
Javascript :: tinymce adding tbale buttons 
Javascript :: node js split 
Javascript :: js array as parameter 
Javascript :: blur js 
Javascript :: usehistory() hook 
Javascript :: js array last element 
Javascript :: math.round in javascript 
Javascript :: unwind mongodb 
Javascript :: javascript last array item 
Javascript :: datatables keep order and page selection page refresh 
Javascript :: return inside ternary operator javascript 
Javascript :: set array length js 
Javascript :: template literal syntax 
Javascript :: create multidimensional array javascript for loop 
Javascript :: Error: ENOENT: no such file or directory, lstat ode_modules@react-navigationcoresrcgetStateFromPath.tsx 
Javascript :: js naming conventions 
ADD CONTENT
Topic
Content
Source link
Name
8+1 =