Similar to as javascript array.

But you would need to specify the types of the parameters and also a return type. Yes you could configure your setup to not care about these things, but then that would defeat the object of using typescript.

export function shuffle<T>(array: T[]): T[] {
    let currentIndex = array.length,  randomIndex;

    // While there remain elements to shuffle.
    while (currentIndex != 0) {
  
      // Pick a remaining element.
      randomIndex = Math.floor(Math.random() * currentIndex);
      currentIndex--;
  
      // And swap it with the current element.
      [array[currentIndex], array[randomIndex]] = [
        array[randomIndex], array[currentIndex]];
    }
  
    return array;
};

You can get different options of shuffle from this question.

Answer from Sergii Rudenko on Stack Overflow
🌐
DevGenius
blog.devgenius.io › mastering-array-shuffling-in-typescript-techniques-and-examples-7cd5eef0eb1e
Mastering Array Shuffling in TypeScript: Techniques and Examples | by Popa Vlad | Dev Genius
March 6, 2025 - function shuffleArray<T>(array: T[]): T[] { const length = array.length; for (let i = length - 1; i > 0; i--) { const j = Math.floor(Math.random() * (i + 1)); [array[i], array[j]] = [array[j], array[i]]; } return array; } // Example usage: const ...
🌐
freeCodeCamp
freecodecamp.org › news › how-to-shuffle-an-array-of-items-using-javascript-or-typescript
How to Shuffle an Array of Items Using JavaScript or TypeScript
June 5, 2023 - The following examples are written in TypeScript, but they work in exactly the same way using plain JavaScript. You just simply need to remove the :type syntax from all function parameters.
🌐
npm
npmjs.com › package › @types › shuffle-array
@types/shuffle-array - npm
declare namespace shuffleArray { /** * copy - Sets if should return a shuffled copy of the given array. By default it's a falsy value. * rng - Specifies a custom random number generator. */ interface ShuffleOptions { copy?: boolean; rng?: () => number; } /** * picks - Specifies how many random elements you want to pick.
      » npm install @types/shuffle-array
    
🌐
Quora
quora.com › How-do-you-shuffle-an-array-of-items-using-JavaScript-or-TypeScript
How to shuffle an array of items using JavaScript or TypeScript - Quora
How do transpilers like TypeScript make working with JavaScript better, and why do developers prefer them? ... If memory is not a problem, use two arrays, one filled with random numbers, sort it. With each swap, swap the elements in the array you wanted randomized. When the sorting is done, the other array is shuffled.
🌐
Sandro Maglione
sandromaglione.com › articles › software › pure function to shuffle an array in typescript using fp-ts
Pure function to shuffle an array in Typescript using fp-ts | Sandro Maglione
January 16, 2022 - import * as IO from 'fp-ts/IO'; /** Shuffle randomly the given array, algorithm from https://stackoverflow.com/a/12646864/7033357 */ export const shuffle = <T>(array: T[]): IO.IO<T[]> => () => { const source = [...array]; for (let i = source.length - 1; i > 0; i--) { const j = Math.floor(Math.random() * (i + 1)); [source[i], source[j]] = [source[j], source[i]]; } return source; };
🌐
Decipher
decipher.dev › shuffle
shuffle | 30 Seconds of Typescript - Decipher.dev
Use the Fisher-Yates algorithm to reorder the elements of the array. typescript · const shuffle = ([...arr]) => { let m = arr.length; while (m) { const i = Math.floor(Math.random() * m--); [arr[m], arr[i]] = [arr[i], arr[m]]; } return arr; }; typescript ·
Find elsewhere
🌐
GitBook
basarat.gitbook.io › algorithms › shuffling
Shuffling | Algorithms in TypeScript
December 31, 2019 - Remember random number generation / assiging an item to an array is O(1), so its just n iteration of O(1) ... function shuffleInPlace<T>(array: T[]): T[] { // if it's 1 or 0 items, just return if (array.length <= 1) return array; // For each index in array for (let i = 0; i < array.length; i++) { // choose a random not-yet-placed item to place there // must be an item AFTER the current item, because the stuff // before has all already been placed const randomChoiceIndex = getRandom(i, array.length - 1); // place our random choice in the spot by swapping [array[i], array[randomChoiceIndex]] = [array[randomChoiceIndex], array[i]]; } return array; }
🌐
Es-toolkit
es-toolkit.dev › reference › array › shuffle.html
shuffle | es-toolkit
Returns a new array with the elements randomly shuffled. typescript · const shuffled = shuffle(arr); Use shuffle when you want to randomly shuffle the elements in an array. It uses the Fisher-Yates algorithm to ensure perfect random shuffling ...
🌐
DeveloperMemos
developermemos.com › posts › shuffle-list-typescript
Shuffling a List with TypeScript | DeveloperMemos
August 27, 2023 - In the above code, the shuffle ... at index j. Another approach to shuffle a list in TypeScript is by using the sort method with a custom random comparator....
🌐
Bomberbot
bomberbot.com › typescript › how-to-shuffle-an-array-of-items-using-javascript-or-typescript
How to Shuffle an Array of Items Using JavaScript or TypeScript - Bomberbot
May 14, 2025 - The space complexity is O(n) in the worst case due to the recursion stack and the temporary arrays created during merging. While this recursive implementation is interesting from a theoretical perspective, the iterative Fisher-Yates shuffle is generally preferable in practice due to its simplicity and optimal O(n) time and O(1) space complexity. One advantage of using TypeScript is that we can define generic functions that work with arrays of any type.
🌐
JavaScript.info
javascript.info › tutorial › the javascript language › data types › array methods
Shuffle an array
The idea is to walk the array in the reverse order and swap each element with a random one before it: function shuffle(array) { for (let i = array.length - 1; i > 0; i--) { let j = Math.floor(Math.random() * (i + 1)); // random index from 0 ...
🌐
Webdevtutor
webdevtutor.net › blog › typescript-array-shuffle
Mastering Array Shuffling in TypeScript
In conclusion, array shuffling in TypeScript can be achieved using various methods such as the Fisher-Yates shuffle algorithm or utilizing TypeScript libraries like lodash. Understanding these techniques will help you efficiently shuffle arrays in your TypeScript projects.
🌐
npm
npmjs.com › package › array-shuffle
array-shuffle - npm
February 2, 2026 - import {arrayToShuffled, arrayShuffle} from 'array-shuffle'; // Create a new shuffled array const shuffled = arrayToShuffled([1, 2, 3, 4, 5, 6]); //=> [3, 5, 4, 1, 2, 6] // Shuffle in-place const array = [1, 2, 3, 4, 5, 6]; arrayShuffle(array); ...
      » npm install array-shuffle
    
Published   Feb 02, 2026
Version   4.1.0
Author   Sindre Sorhus
🌐
GitHub
github.com › neo › shuffle.ts
GitHub - neo/shuffle.ts: Shuffle an Array in TypeScript
November 23, 2017 - Shuffle an Array in TypeScript. Contribute to neo/shuffle.ts development by creating an account on GitHub.
Author   neo
🌐
egghead.io
egghead.io › lessons › typescript-shuffle-an-array
Shuffle an array | egghead.io
July 27, 2017 - In each iteration i, we simply put a random item from the unshuffled position into the ith position within the shuffled position. Hence, increasing the length of the shuffled position. This way we eventually end up with a fully shuffled array. [02:45] Let's implement this algorithm here in TypeScript.
🌐
Webdevtutor
webdevtutor.net › blog › typescript-scramble-array
Scrambling an Array in TypeScript: A Guide to Shuffling and Rearranging Your Data
Another method for scrambling an array is to use the Math.random() function to randomly select elements from the array and swap them. Here's an example implementation of random shuffling in TypeScript: