JavaScript常用技巧之字符串操作

1、首字母大写

str.replace(/w+/g, function (word) {
    return word.substring(0, 1).toLowerCase() + word.substring(1);
});

2、截取字符串最后几位

str.substring(str.length-X)

3、生成随机字符串

Math.random().toString(36).substring(7)

4、解析 Base64

new Buffer(base64str, 'base64').toString();
原文地址:https://www.cnblogs.com/yudis/p/7103048.html