Remove extraneous characters in JavaScript