14.写一个function ,清除字符串前后的空格

function trim(str) {

    if (str && typeof str === "string") {
        return str.replace(/(^s*)|(s*)$/g,""); //去除前后空白符
    }
}
原文地址:https://www.cnblogs.com/dream111/p/13466590.html