---
title: "Discussion on \"Simple snippet to shuffle array\" | Hashnode"
description: "Discussion on \"Simple snippet to shuffle array\". If you need to shuffle the elements of an array, you can use this simple function:\nfunction shuffle(array) {\n  const copy = [...array]\n\n  return copy.sort(() => Math.random() - 0.5)\n}\n\nThe algorithm\n\nCreates a copy of the parameter to not modify the ..."
url: "https://hashnode.com/posts/simple-snippet-to-shuffle-array/61e09a901f35f37864466894"
---

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

Discussion

# [Simple snippet to shuffle array](https://blog.gabrielrufino.com/simple-snippet-to-shuffle-array?utm_source=hashnode&utm_medium=feed)

If you need to shuffle the elements of an array, you can use this simple function: function shuffle(array) { const copy = \[...array\] return copy.sort(() => Math.random() - 0.5) } The algorithm Creates a copy of the parameter to not modify the ...

Jul 24, 2020 · 1 min read · blog.gabrielrufino.com  
Read the article

## Written by

[Gabriel Rufino](https://hashnode.com/@gabrielrufino)

@gabrielrufino · Pernambuco, BR

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

Software Developer | Back-end

## Responses

Markdown supported · ⌘↵ to post

No responses yet.
