Remove all white space from string JavaScript [duplicate] December 21, 2023 by Tarik Use this: str.replace(/\s+/g, ''); Instead of this: str.trim()