示例字符串 var userId= '6hjf2342b4237p42bkj32149214';code
要求:保留userId后22位字符,前面的字符用'...'代替字符串
方法一:(substring)string
userId.substring(userId.length - 22, userId.length)
方法二:(match匹配)方法
userId.match(/.{22}$/)[0] 或者userId.match(/.*(.{22})/)[1]
方法三:(slice)co
userId.slice(-22) //推荐这个,比较简单,-22表示取右边22个字符