Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
</body>
</html>
 
function flatten(arr) {
  return [].concat(...arr)
}
function deepFlatten(arr) {
  return flatten(           // return shalowly flattened array
    arr.map(x=>             // with each x in array
      Array.isArray(x)      // is x an array?
        ? deepFlatten(x)    // if yes, return deeply flattened x
        : x                 // if no, return just x
    )
  )
}
var fourDimensionalArray = [
  [
    [
      [1, 2],
      [3, 4]
    ],
    [
      [5, 6],
      [7, 8]
    ]
  ],
  [
    [
      [9, 10],
      [11, 12]
    ],
    [
      [13, 14],
      [15, 16]
    ]
  ]
];
console.log(deepFlatten(fourDimensionalArray))
Output 300px

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
Gothdopro
0viewers