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>
 
var myArray = [[1, 2],[3, 4, 5], [6, 7, 8, 9]];
// Solution 1
var myNewArray1 = [].concat.apply([], myArray);
console.log(myNewArray1);
// Solution 2
var myNewArray2 = myArray.reduce(function(a, b) {
  return a.concat(b);
});
console.log(myNewArray2);
// Solution 3
var myNewArray3 = [];
for (var i = 0; i < myArray.length; ++i) {
  for (var j = 0; j < myArray[i].length; ++j)
    myNewArray3.push(myArray[i][j]);
}
console.log(myNewArray3);
var myNewArray4 = [].concat(...myArray);
console.log(myNewArray4);
Output

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

Dismiss x
public
Bin info
richzwpro
0viewers