Extremely simple solution, but kind of fun because it's a chance to use recursion:
<script type=text/javascript> var a = [1,2,[5,6,7], 8, [9,10,[11,12],13], 14]; function flatten( oArray ) { var retVal = []; for (var i=0;i<oArray.length;i++) { if (!isArray( oArray[i]) ) { retVal.push( oArray[i] ); } else { var tempFlatt = flatten(oArray[i]); for (var j=0;j<tempFlatt.length;j++) { retVal.push( tempFlatt[j] ); } } } return retVal; } function isArray( anElement ) { return (typeof anElement=="object" && anElement.constructor == Array); } alert(flatten(a)); </script>