---
title: "Comment by Evan Brodie on \"Sorting in JavaScript\" | Hashnode"
description: "Great article, but you skipped over what I believe is the biggest quirk of Array.prototype.sort() : sorting is applied in-place on the array, ie it mutates the"
url: "https://hashnode.com/posts/sorting-in-javascript/61e525c98a425719c1735ae4/comment/61e6d1bf0204273bdcb0f3c6"
---

[Discussion](https://hashnode.com/posts/sorting-in-javascript/61e525c98a425719c1735ae4)

Comment [Sorting in JavaScript](https://hashnode.com/posts/sorting-in-javascript/61e525c98a425719c1735ae4)

[Evan Brodie](https://hashnode.com/@ecbrodie)

[Jan 18, 2022](https://hashnode.com/posts/sorting-in-javascript/61e525c98a425719c1735ae4/comment/61e6d1bf0204273bdcb0f3c6)

Great article, but you skipped over what I believe is the biggest quirk of `Array.prototype.sort()`: _sorting is applied in-place on the array, ie it mutates the array!_ This is not immediately apparent if you were to do something like `const sortedArray = unsortedArray.sort()`, that you just changed the `unsortedArray` too. I have worked on several teams who have been burned by hard-to-find bugs caused by this behaviour, which is not easily caught by a linter. I'd advise you mention this in your article too.

[Rupert McKay](https://hashnode.com/@fildon)

[Jan 18, 2022](https://hashnode.com/posts/sorting-in-javascript/61e525c98a425719c1735ae4/comment/61e6d1bf0204273bdcb0f3c6#reply-61e6da050204273bdcb0f471)

That's a great point! I'll update the article to make that clear.

EDIT: I have made an update now and called out the in-place sorting in a few parts of the post.

Thanks again for pointing this out!
