str.removeWhitespaces()

// 🔸 str.removeWhitespaces()
String.prototype.removeWhitespaces = function() {
    return this.replace(/\s+/g, '');
};

💈範例:

// multi-line string
let str = `
as     void     async     while
`;

str.removeWhitespaces()    // "asvoidasyncwhile"

Last updated

Was this helpful?