{"id":1601,"date":"2014-11-18T14:29:04","date_gmt":"2014-11-18T12:29:04","guid":{"rendered":"http:\/\/www.webcodegeeks.com\/?p=1601"},"modified":"2018-06-20T17:03:01","modified_gmt":"2018-06-20T14:03:01","slug":"javascript-sort-array-example","status":"publish","type":"post","link":"https:\/\/www.webcodegeeks.com\/javascript\/javascript-sort-array-example\/","title":{"rendered":"JavaScript Sort Array Example"},"content":{"rendered":"<p>Array sorting is a key development technique applied in a variety of situations. Below we&#8217;ll show you exactly how to use Sort Array, be it sorting an array of numbers, names or structures, ascending, descending or even randomizing and reversing an array.<\/p>\n<p>[ulp id=&#8217;tCIwOngQUb3zSUuF&#8217;]<\/p>\n<h2>The sort() method<\/h2>\n<p>The <code>sort()<\/code> method sorts the elements of an array and returns the array. The sort is not necessary stable (read <a href=\"https:\/\/en.wikipedia.org\/wiki\/Sorting_algorithm#Stability\" target=\"_blank\" rel=\"noopener\">here<\/a> for more information). The syntax for the function is like this:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\narr.sort(&#x5B;compareFunction])\r\n<\/pre>\n<p>The <code>sort()<\/code> function takes the optional parameter <code>compareFunction<\/code>. This parameter specifies the sort order, and if omitted the sorting will go according to string <a href=\"http:\/\/www.unicode.org\/\" target=\"_blank\" rel=\"noopener\">Unicode<\/a> code points. What if it&#8217;s not omitted?<\/p>\n<p>In this case the array elements are sorted according to the return value of the compareFunction. Which means, if a and b were two elements being compared then when the return value is less than 0, a is sorted to a lower index than b, if the return value is 0 than they&#8217;re equal, and if the return value is greater than 0, a is sorted to a higher index than b. Beware that <code>compareFunction(a, b)<\/code> must always return the same value when given a specific pair of elements as it&#8217;s arguments. If inconsistent results are returned then the sort order is undefined.<\/p>\n<h2>Sorting strings<\/h2>\n<p>So let&#8217;s get to actually using them. The easiest use of the <code>sort()<\/code> function is sorting an array of strings. The code will go like this:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nvar stringArray = &#x5B;'Blue', 'Humpback', 'Beluga'];\r\n\r\nconsole.log('stringArray:', stringArray.join());\r\nconsole.log('Sorted:', stringArray.sort());\r\n<\/pre>\n<p>We have only declared the array, and printed it as it was originally, and also after sorting. Pretty simple so far.<\/p>\n<h2>Sorting Numbers<\/h2>\n<p>Now let&#8217;s compare numbers:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nvar numberArray = &#x5B;40, 1, 5, 200];\r\n\r\nfunction compareNumbers(a, b) {\r\n    return a - b;\r\n}\r\n\r\nconsole.log('numberArray:', numberArray.join());\r\nconsole.log('Sorted without a compare function:', numberArray.sort());\r\nconsole.log('Sorted with compareNumbers:', numberArray.sort(compareNumbers));\r\n<\/pre>\n<p>The output will look like this:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nnumberArray: 40,1,5,200\r\nSorted without a compare function: 1,200,40,5\r\nSorted with compareNumbers: 1,5,40,200\r\n<\/pre>\n<p>You&#8217;ve certainly noticed that in using sorting without the <code>compareNumbers<\/code> function, the sorting is not correct, as 200 is very much greater than 5. This happens because as we told you in the beginning, the default way of sorting is by considering numbers as strings and comparing them based on Unicode code points.<\/p>\n<h2>Sorting numeric strings<\/h2>\n<p>We saw what happens when we compare strings, and what happens when we compare numbers. What we didn&#8217;t mention is what happens when we compare numeric string. This is the code:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nvar numericStringArray = &#x5B;'80', '9', '700'];\r\n\r\nconsole.log('numericStringArray:', numericStringArray.join());\r\nconsole.log('Sorted without a compare function:', numericStringArray.sort());\r\nconsole.log('Sorted with compareNumbers:', numericStringArray.sort(compareNumbers));\r\n<\/pre>\n<p>And this is how the output will look like:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nnumericStringArray: 80,9,700\r\nSorted without a compare function: 700,80,9\r\nSorted with compareNumbers: 9,80,700\r\n<\/pre>\n<p>So now you see that the numeric strings sorted without a compare function are sorted according to Unicode code points, but with a compare function they are treated entirely like numbers.<\/p>\n<h2>Mixed numeric Arrays<\/h2>\n<p>The other combination of numbers and strings we haven&#8217;t mentioned is a mixed array of numbers of strings. The code will go like this:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nvar mixedNumericArray = &#x5B;'80', '9', '700', 40, 1, 5, 200];\r\n\r\nconsole.log('mixedNumericArray:', mixedNumericArray.join());\r\nconsole.log('Sorted without a compare function:', mixedNumericArray.sort());\r\nconsole.log('Sorted with compareNumbers:', mixedNumericArray.sort(compareNumbers));\r\n<\/pre>\n<p>You might have guessed what the output will look like. Anyway, you can see it below, just to check:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nmixedNumericArray: 80,9,700,40,1,5,200\r\nSorted without a compare function: 1,200,40,5,700,80,9\r\nSorted with compareNumbers: 1,5,9,40,80,200,700\r\n<\/pre>\n<h2>Sorting non-ASCII characters<\/h2>\n<p>By now you now how to sort numbers and strings and whatnot, but if you live in a country which uses special characters (my country uses &#8220;\u00e7&#8221; and &#8220;\u00eb&#8221;) you might be thinking: How do I sort strings that contain those characters?<\/p>\n<p>It&#8217;s very easy: you use the function <code>localeCompare<\/code> like this:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nvar items = &#x5B;'r\u00e9serv\u00e9', 'premier', 'clich\u00e9', 'communiqu\u00e9', 'caf\u00e9', 'adieu'];\r\nitems.sort(function (a, b) {\r\n  return a.localeCompare(b);\r\n});\r\n<\/pre>\n<p>It will turn out this array:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nadieu, caf\u00e9, clich\u00e9, communiqu\u00e9, premier, r\u00e9serv\u00e9\r\n<\/pre>\n<p>As easy as pie.<\/p>\n<h2>Sorting Maps<\/h2>\n<p>Sometimes you will have array elements, so different from each other that you will have no option but to use the <code>compareFunction<\/code> multiple times. As the number of elements, and the complexity of the <code>compareFunction<\/code> increases, the need for using sorting maps increases too. The general idea of sorting maps is to walk the array once and extract the actual values used for sorting in a temporary array, and then sort the temporary array to get the sorted array. This is the list we&#8217;ll sort this time:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nvar list = &#x5B;'Delta', 'alpha', 'CHARLIE', 'bravo'];\r\n<\/pre>\n<p>The temporary holder of position and sort value will look like this:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nvar map = list.map(function(e, i) {\r\n    return { index: i, value: e.toLowerCase() };\r\n})\r\n<\/pre>\n<p>The sorting map&#8217;s code containing the reduced values will be this:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nmap.sort(function(a, b) {\r\n    return +(a.value &gt; b.value) || +(a.value === b.value) - 1;\r\n});\r\n<\/pre>\n<p>And finally, the container for the resulting order is this:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nvar result = map.map(function(e){\r\n    return list&#x5B;e.index];\r\n});\r\n<\/pre>\n<p>So now you can even use sorting maps! But it&#8217;s not all. How about some reversing and randomizing arrays?<\/p>\n<h2>Reversing Arrays<\/h2>\n<p>To reverse array we use the function <code>reverse()<\/code>, which just puts the first element in last place and so on until the last element is placed first. The following code snippet is the creation and reversing of an array:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nvar myArray = &#x5B;'one', 'two', 'three'];\r\nmyArray.reverse(); \r\n\r\nconsole.log(myArray) \/\/ &#x5B;'three', 'two', 'one']\r\n<\/pre>\n<p>Now on to the next exciting thing: Shuffling.<\/p>\n<h2>Randomizing arrays<\/h2>\n<p>The most used and unbiased algorithm for shuffling is the <a href=\"http:\/\/en.wikipedia.org\/wiki\/Fisher%E2%80%93Yates_shuffle\">Fisher-Yates Shuffle<\/a> also known as Knuth Shuffle (you can also find it on <a href=\"https:\/\/github.com\/coolaj86\/knuth-shuffle\">Github<\/a>). The code for it will go like this:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nfunction shuffle(array) {\r\n  var currentIndex = array.length, temporaryValue, randomIndex ;\r\n\r\n  \/\/ While there remain elements to shuffle...\r\n  while (0 !== currentIndex) {\r\n\r\n    \/\/ Pick a remaining element...\r\n    randomIndex = Math.floor(Math.random() * currentIndex);\r\n    currentIndex -= 1;\r\n\r\n    \/\/ And swap it with the current element.\r\n    temporaryValue = array&#x5B;currentIndex];\r\n    array&#x5B;currentIndex] = array&#x5B;randomIndex];\r\n    array&#x5B;randomIndex] = temporaryValue;\r\n  }\r\n\r\n  return array;\r\n}\r\n\r\nvar arr = &#x5B;2, 11, 37, 42];\r\nshuffle(arr);\r\nconsole.log(arr);\r\n<\/pre>\n<p>Let&#8217;s explain what we did there. First we set the condition, which is &#8220;until the last element of the array&#8221;. Then we pick one of the remaining elements, starting from the one we&#8217;re at currently, and then we pick a remaining element, after which we reduce the current index by 1. Then we swap that with the current element. The function returns the array.<\/p>\n<p>In the last part of the code we have the actual usage of the function, by giving values to the array.<\/p>\n<p>And that folks, is how we randomize an array.<\/p>\n<h2>Download the source code<\/h2>\n<p>This was an example of array sorting, using JavaScript.<\/p>\n<div class=\"download\"><strong>Download<\/strong><br \/>\nYou can download the source code for this example here: <strong><a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/11\/SortArray.zip\">SortArray<\/a><\/strong><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Array sorting is a key development technique applied in a variety of situations. Below we&#8217;ll show you exactly how to use Sort Array, be it sorting an array of numbers, names or structures, ascending, descending or even randomizing and reversing an array. [ulp id=&#8217;tCIwOngQUb3zSUuF&#8217;] The sort() method The sort() method sorts the elements of an &hellip;<\/p>\n","protected":false},"author":25,"featured_media":920,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[],"class_list":["post-1601","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-javascript"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>JavaScript Sort Array Example - Web Code Geeks - 2026<\/title>\n<meta name=\"description\" content=\"Interested to learn about Sort Array in JS? Check our Example on how to sort an array of numbers or structures ascending\/descending\/randomizing\/reversing!\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.webcodegeeks.com\/javascript\/javascript-sort-array-example\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"JavaScript Sort Array Example - Web Code Geeks - 2026\" \/>\n<meta property=\"og:description\" content=\"Interested to learn about Sort Array in JS? Check our Example on how to sort an array of numbers or structures ascending\/descending\/randomizing\/reversing!\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.webcodegeeks.com\/javascript\/javascript-sort-array-example\/\" \/>\n<meta property=\"og:site_name\" content=\"Web Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/webcodegeeks\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/era.balliu.7\" \/>\n<meta property=\"article:published_time\" content=\"2014-11-18T12:29:04+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2018-06-20T14:03:01+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/js-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Era Balliu\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@BalliuEra\" \/>\n<meta name=\"twitter:site\" content=\"@webcodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Era Balliu\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/javascript-sort-array-example\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/javascript-sort-array-example\/\"},\"author\":{\"name\":\"Era Balliu\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/c27ecf40c810e6396ba93ffb829c7b0e\"},\"headline\":\"JavaScript Sort Array Example\",\"datePublished\":\"2014-11-18T12:29:04+00:00\",\"dateModified\":\"2018-06-20T14:03:01+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/javascript-sort-array-example\/\"},\"wordCount\":1153,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/javascript-sort-array-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/js-logo.jpg\",\"articleSection\":[\"JavaScript\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.webcodegeeks.com\/javascript\/javascript-sort-array-example\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/javascript-sort-array-example\/\",\"url\":\"https:\/\/www.webcodegeeks.com\/javascript\/javascript-sort-array-example\/\",\"name\":\"JavaScript Sort Array Example - Web Code Geeks - 2026\",\"isPartOf\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/javascript-sort-array-example\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/javascript-sort-array-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/js-logo.jpg\",\"datePublished\":\"2014-11-18T12:29:04+00:00\",\"dateModified\":\"2018-06-20T14:03:01+00:00\",\"description\":\"Interested to learn about Sort Array in JS? Check our Example on how to sort an array of numbers or structures ascending\/descending\/randomizing\/reversing!\",\"breadcrumb\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/javascript-sort-array-example\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.webcodegeeks.com\/javascript\/javascript-sort-array-example\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/javascript-sort-array-example\/#primaryimage\",\"url\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/js-logo.jpg\",\"contentUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/js-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/javascript-sort-array-example\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.webcodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"JavaScript\",\"item\":\"https:\/\/www.webcodegeeks.com\/category\/javascript\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"JavaScript Sort Array Example\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#website\",\"url\":\"https:\/\/www.webcodegeeks.com\/\",\"name\":\"Web Code Geeks\",\"description\":\"Web Developers Resource Center\",\"publisher\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.webcodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/www.webcodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/webcodegeeks\",\"https:\/\/x.com\/webcodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/c27ecf40c810e6396ba93ffb829c7b0e\",\"name\":\"Era Balliu\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/f6adddf7eada210f682608fea9d8159441369ec622998a5851a447e0a2bfa3f3?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/f6adddf7eada210f682608fea9d8159441369ec622998a5851a447e0a2bfa3f3?s=96&d=mm&r=g\",\"caption\":\"Era Balliu\"},\"description\":\"Era is a Telecommunications Engineering student, with a great passion for new technologies. Up until now she has been coding with HTML\/CSS, Bootstrap and other front-end coding languages and frameworks, and her recent love is Angular JS.\",\"sameAs\":[\"http:\/\/www.webcodegeeks.com\/\",\"https:\/\/www.facebook.com\/era.balliu.7\",\"https:\/\/www.instagram.com\/eraballiu\/\",\"https:\/\/www.linkedin.com\/in\/eraballiu\",\"https:\/\/www.pinterest.com\/001r2gw0jt0ln6d\/\",\"https:\/\/x.com\/BalliuEra\",\"https:\/\/www.youtube.com\/c\/eraballiu\"],\"url\":\"https:\/\/www.webcodegeeks.com\/author\/era-balliu\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"JavaScript Sort Array Example - Web Code Geeks - 2026","description":"Interested to learn about Sort Array in JS? Check our Example on how to sort an array of numbers or structures ascending\/descending\/randomizing\/reversing!","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.webcodegeeks.com\/javascript\/javascript-sort-array-example\/","og_locale":"en_US","og_type":"article","og_title":"JavaScript Sort Array Example - Web Code Geeks - 2026","og_description":"Interested to learn about Sort Array in JS? Check our Example on how to sort an array of numbers or structures ascending\/descending\/randomizing\/reversing!","og_url":"https:\/\/www.webcodegeeks.com\/javascript\/javascript-sort-array-example\/","og_site_name":"Web Code Geeks","article_publisher":"https:\/\/www.facebook.com\/webcodegeeks","article_author":"https:\/\/www.facebook.com\/era.balliu.7","article_published_time":"2014-11-18T12:29:04+00:00","article_modified_time":"2018-06-20T14:03:01+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/js-logo.jpg","type":"image\/jpeg"}],"author":"Era Balliu","twitter_card":"summary_large_image","twitter_creator":"@BalliuEra","twitter_site":"@webcodegeeks","twitter_misc":{"Written by":"Era Balliu","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.webcodegeeks.com\/javascript\/javascript-sort-array-example\/#article","isPartOf":{"@id":"https:\/\/www.webcodegeeks.com\/javascript\/javascript-sort-array-example\/"},"author":{"name":"Era Balliu","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/c27ecf40c810e6396ba93ffb829c7b0e"},"headline":"JavaScript Sort Array Example","datePublished":"2014-11-18T12:29:04+00:00","dateModified":"2018-06-20T14:03:01+00:00","mainEntityOfPage":{"@id":"https:\/\/www.webcodegeeks.com\/javascript\/javascript-sort-array-example\/"},"wordCount":1153,"commentCount":0,"publisher":{"@id":"https:\/\/www.webcodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.webcodegeeks.com\/javascript\/javascript-sort-array-example\/#primaryimage"},"thumbnailUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/js-logo.jpg","articleSection":["JavaScript"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.webcodegeeks.com\/javascript\/javascript-sort-array-example\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.webcodegeeks.com\/javascript\/javascript-sort-array-example\/","url":"https:\/\/www.webcodegeeks.com\/javascript\/javascript-sort-array-example\/","name":"JavaScript Sort Array Example - Web Code Geeks - 2026","isPartOf":{"@id":"https:\/\/www.webcodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.webcodegeeks.com\/javascript\/javascript-sort-array-example\/#primaryimage"},"image":{"@id":"https:\/\/www.webcodegeeks.com\/javascript\/javascript-sort-array-example\/#primaryimage"},"thumbnailUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/js-logo.jpg","datePublished":"2014-11-18T12:29:04+00:00","dateModified":"2018-06-20T14:03:01+00:00","description":"Interested to learn about Sort Array in JS? Check our Example on how to sort an array of numbers or structures ascending\/descending\/randomizing\/reversing!","breadcrumb":{"@id":"https:\/\/www.webcodegeeks.com\/javascript\/javascript-sort-array-example\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.webcodegeeks.com\/javascript\/javascript-sort-array-example\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/javascript\/javascript-sort-array-example\/#primaryimage","url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/js-logo.jpg","contentUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/js-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/www.webcodegeeks.com\/javascript\/javascript-sort-array-example\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.webcodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"JavaScript","item":"https:\/\/www.webcodegeeks.com\/category\/javascript\/"},{"@type":"ListItem","position":3,"name":"JavaScript Sort Array Example"}]},{"@type":"WebSite","@id":"https:\/\/www.webcodegeeks.com\/#website","url":"https:\/\/www.webcodegeeks.com\/","name":"Web Code Geeks","description":"Web Developers Resource Center","publisher":{"@id":"https:\/\/www.webcodegeeks.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.webcodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.webcodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.webcodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/webcodegeeks","https:\/\/x.com\/webcodegeeks"]},{"@type":"Person","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/c27ecf40c810e6396ba93ffb829c7b0e","name":"Era Balliu","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/f6adddf7eada210f682608fea9d8159441369ec622998a5851a447e0a2bfa3f3?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/f6adddf7eada210f682608fea9d8159441369ec622998a5851a447e0a2bfa3f3?s=96&d=mm&r=g","caption":"Era Balliu"},"description":"Era is a Telecommunications Engineering student, with a great passion for new technologies. Up until now she has been coding with HTML\/CSS, Bootstrap and other front-end coding languages and frameworks, and her recent love is Angular JS.","sameAs":["http:\/\/www.webcodegeeks.com\/","https:\/\/www.facebook.com\/era.balliu.7","https:\/\/www.instagram.com\/eraballiu\/","https:\/\/www.linkedin.com\/in\/eraballiu","https:\/\/www.pinterest.com\/001r2gw0jt0ln6d\/","https:\/\/x.com\/BalliuEra","https:\/\/www.youtube.com\/c\/eraballiu"],"url":"https:\/\/www.webcodegeeks.com\/author\/era-balliu\/"}]}},"_links":{"self":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts\/1601","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/users\/25"}],"replies":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/comments?post=1601"}],"version-history":[{"count":0,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts\/1601\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/media\/920"}],"wp:attachment":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/media?parent=1601"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/categories?post=1601"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/tags?post=1601"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}