---
title: "Discussion on \"Sort method to sort arrays\" | Hashnode"
description: "Discussion on \"Sort method to sort arrays\". The sort method sorts the elements of an array according to the callback function.\nFor example on an array of numbers:\nfunction ascendingOrder(arr) {\n  return arr.sort(function(a, b) {\n    return a - b;\n  });\n}\n\nascendingOrder([1, 5, 2, 3, 4]); // =>..."
url: "https://hashnode.com/posts/sort-method-to-sort-arrays/61b72facd2a5c9036e6ef466"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Sort method to sort arrays](https://plasebo.hashnode.dev/sort-method-to-sort-arrays?utm_source=hashnode&utm_medium=feed)

The sort method sorts the elements of an array according to the callback function. For example on an array of numbers: function ascendingOrder(arr) { return arr.sort(function(a, b) { return a - b; }); } ascendingOrder(\[1, 5, 2, 3, 4\]); // =>...

Dec 13, 2021 · 2 min read · plasebo.hashnode.dev  
Read the article

-   [#javascript](https://hashnode.com/tag/javascript)
-   [#js](https://hashnode.com/tag/js)
-   [#array](https://hashnode.com/tag/array)
-   [#array-methods](https://hashnode.com/tag/array-methods)

## Written by

[Shane Plasebo](https://hashnode.com/@Plasebo)

@Plasebo · Moka, Mauritius

  
[View profile](https://hashnode.com/@Plasebo)

## Responses

Markdown supported · ⌘↵ to post

No responses yet.
