Flatten a multi-dimension array in JavaScript.