Array.prototype.flatten >= 0.1.4

Purpose

Flatten the array by returning a single-dimensional copy

Syntax

Array#flatten ( Numberlimit= Infinity );

Parameters

limit
Recursive limit

Return values

Array

New array instance

Examples

Return a single dimension copy of the array

var original = [0,1,[2,3,[4,5,[6,7]]], 8, [9,10]];

original.flatten();>>> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

Set recursive limit

var arr = [0, 1, [2, [3, 4]]];

arr.flatten(1);>>> [0, 1, 2, [3, 4]]