1、如何快速排序一个数组 let arr = [3, 2, 4, 6, 5, 1]; arr.sort(function (a, b) { return a.startTime > b.startTime ? 1 : -1; }); //arr = [1,2,3,4,5,6]; //ps:排序时间也可以用 非常实用。 2、map和forEach不同之处; let arr = [1, 2, 3]; let a1 = arr.map(liem => { return liem; }) //a1 = [1,2,3]; let a1 = arr.forEach(liem => { return liem; }) //a2 = undefined; //ps:map在循环里面return 会返回内容 开发中可以处理一下数组 3、快速获取指定日期方法; function getNumTime(num) { /* num 获取当天多少天后的日期 */ let today = new Date().getTime(); let lastDay = today + 60 * 60 * 1000 * 24 * num; //获取30天后的日期 let lastTime = new Date(lastDay).toISOString().split('T')[0]; return lastTime; }; //ps: //getNumTime(0)今天日期 yyyy-MM-dd //getNumTime(1)明天天日期 yyyy-MM-dd 4、快速处理电话加密 function phoneEncryption(value) { if (!value) { return; } value = value + ""; return value.substr(0, 3) + "****" + value.substr(7, 4); } //ps: //phoneEncryption(15999999999) = 159****9999; 5、快速获取url地址后面参数; function GetRequest() { var url = location.search; //获取url中"?"符后的字串 var theRequest = new Object(); if (url.indexOf("?") != -1) { var str = url.substr(1); strs = str.split("&"); for (var i = 0; i < strs.length; i++) { theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]); } } return theRequest; }; //ps: //GetRequest().参数名 = 获取url携带参数 6、时间格式换算成秒 (例如:HH: mm) function formatSeconds(value) { var theTime = value.split(':');// 需要转换的时间秒 var num = theTime[2] * 1; if ((theTime[1] * 1) > 0) { num += theTime[1] * 60; } if ((theTime[0] * 1) > 0) { num += theTime[0] * 3600; } return num; } //ps: 做抢购倒计时很实用 //formatSeconds("2:00") = 120秒