Replace square brackets in JS