js uses regular expressions to remove the spaces before and after the string

Remove the spaces before and after the string


1. Example
Insert picture description here
2. Method

trim: function (obj) {
    
    
        if (typeof obj === 'string') {
    
    
            return obj.replace(/^\s+|\s+$/gm, '');
        } else {
    
    
            return obj
        }
 }

Guess you like

Origin blog.csdn.net/zcbmwasd/article/details/113112506