splitting and joining arrays in js