JS: 2D array flattening