src code

instance method Array#flatten

Array#flatten() → Array

Returns a flattened (one-dimensional) copy of the array, leaving the original array unchanged.

Nested arrays are recursively injected inline. This can prove very useful when handling the results of a recursive collection algorithm, for instance.

Example
var a = ['frank', ['bob', 'lisa'], ['jill', ['tom', 'sally']]];
var b = a.flatten();
// a -> ['frank', ['bob', 'lisa'], ['jill', ['tom', 'sally']]]
// b -> ['frank', 'bob', 'lisa', 'jill', 'tom', 'sally']