Saturday, October 11, 2025
HomeLanguagesJavascriptD3.js | d3.permute() function

D3.js | d3.permute() function

The d3.permute() function in D3.js is used to permutate the elements of the given array with a given specified array of indexes and it returns the array containing the corresponding element for each given indexes.

Syntax:

d3.permute(array, Index)

Parameters: This function accepts two parameters which are mentioned above and described below:

  • Array: It is the array of elements on which permutation is performed.
  • Index: It is the given index which is used to permutate the given array elements and correspondingly returns the elements of the given array into an array.

Return Value: It returns the array of permuted elements.

Below programs illustrate the d3.permute() function in D3.js.

Example 1: In the below code, the permutation is being done on the elements of the given array with a given specified array of indexes and it returns the array containing the corresponding element for each given indexes.




<html>
  
<head>
    <title>
      Getting permuted array of elements
  </title>
</head>
  
<body>
    <script src='https://d3js.org/d3.v4.min.js'>
  </script>
  
    <script>
        // Initialising the arrays of elements
        var Array1 = ["gfg", "Geek", "Geeks", "neveropen"];
        var Array2 = ["a", "ab", "abc", "abcd"];
  
        // Initialising the indexes
        var Index1 = [1, 2, 0, 3];
        var Index2 = [3, 1, 2, 0];
  
        // Calling to d3.permute() function
        A = d3.permute(Array1, Index1);
        B = d3.permute(Array2, Index2);
  
        // Getting permuted array of elements
        document.write(A + "<br>");
        document.write(B + "<br>");
    </script>
</body>
  
</html>


Output:

Geek, Geeks, gfg, neveropen
abcd, ab, abc, a

Example 2:




<html>
  
<head>
    <title>
      Getting permuted array of elements
  </title>
</head>
  
<body>
    <script src='https://d3js.org/d3.v4.min.js'>
  </script>
  
    <script>
        // Taking the array of elements and 
        // indexes as the parameters
        // for the function d3.permute()
        A = d3.permute(["Hi", "Hello", "Greet"], [1, 2, 0]);
        B = d3.permute(["Ram", "Shyam", "Geeta", "Hari"],
                       [3, 1, 2, 0]);
  
        // Getting permuted array of elements
        document.write(A + "<br>");
        document.write(B + "<br>");
    </script>
</body>
  
</html>


Output:

Hello, Greet, Hi
Hari, Shyam, Geeta, Ram

Ref: https://devdocs.io/d3~4/d3-array#permute

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32350 POSTS0 COMMENTS
Milvus
87 POSTS0 COMMENTS
Nango Kala
6720 POSTS0 COMMENTS
Nicole Veronica
11882 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11941 POSTS0 COMMENTS
Shaida Kate Naidoo
6839 POSTS0 COMMENTS
Ted Musemwa
7101 POSTS0 COMMENTS
Thapelo Manthata
6794 POSTS0 COMMENTS
Umr Jansen
6794 POSTS0 COMMENTS