Flatten a multi-dimensional array in JavaScript.