js使用的工具方法(不断积累)!!

xiaoxiao2021-02-28  86

1.去掉字符串前后的空格!

function(str) { str = str.replace(/^(\s|\u00A0)+/, ''); for (var i = str.length - 1; i >= 0; i--) { if (/\S/.test(str.charAt(i))) { str = str.substring(0, i + 1); break; } } return str; } 2.字符串替换 date.replace(/T/,"a");/T/:T是被替换的字符 "a":a是替换的字符 3.js转化对象,避免传递引用!

deepCopy(a:any){ if(!(a instanceof Object) || (a instanceof Array)){ return a; } let b = {}; for(let attr in a){ b[attr] = this.deepCopy(a[attr]); } return b; } 4. 计算时间差:两个变量都是时间格式 let day = (endDate-beginDate)/(1000*60*60*24) + 1; 加减时间:加六天 endDate1.setDate(endDate1.getDate()+6);
转载请注明原文地址: https://www.6miu.com/read-82698.html

最新回复(0)