Skip to content

Instantly share code, notes, and snippets.

@tonkatsu7
Created December 16, 2017 06:17
Show Gist options
  • Save tonkatsu7/da13751a9ad08ecc773c2c76b808a858 to your computer and use it in GitHub Desktop.
Save tonkatsu7/da13751a9ad08ecc773c2c76b808a858 to your computer and use it in GitHub Desktop.
Flatten a javascript array
var arr1 = ['a', 'b', 'c'];
console.log(arr1.length);
var arr2 = ['d', 'e', 'f'];
console.log(arr2.length);
var arr3 = ['g', 'h', 'i'];
console.log(arr3.length);
var nested = [arr1, arr2, arr3];
console.log('nested=' + nested);
console.log(nested.length);
var flattened = [].concat.apply([], nested);
console.log('resut=' + flattened);
console.log(flattened.length);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment