Skip to content

Instantly share code, notes, and snippets.

@rustam-swe
Created June 23, 2020 18:56
Show Gist options
  • Save rustam-swe/3e7c38feed6190a36146946b43cc7f67 to your computer and use it in GitHub Desktop.
Save rustam-swe/3e7c38feed6190a36146946b43cc7f67 to your computer and use it in GitHub Desktop.
Makes multidimensional array from an existing array
function makeMultidimensionalArray(inputArray, arraysCount = 20, arrayLength = 1) {
return [...Array(arraysCount)] // Create an array with number of elements (default = 20)
.map((item, index) => {
return Array(arrayLength).fill(inputArray[index]) // Make an inner array with the length of "index" (default = 1)
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment