let keyArr = path.split('.'); //根据.切割
let i = 0;
for (let len = keyArr.length; i < len - 1; ++i) {
if (!tempObj && !strict) break;
let key = keyArr;
if (key in tempObj) {
tempObj = tempObj[key];
} else {
if (strict) {//开启严格模式,没找到对应key值,抛出错误
throw new Error('please transfer a valid prop path to form item!');
}
break;
}
}
return {
o: tempObj, //原始数据
k: keyArr, //key值
v: tempObj ? tempObj[keyArr] : null // key值对应的值
};
};
31、GetUrlParam:获取Url参数,返回一个对象
function GetUrlParam(){
let url = document.location.toString();
let arrObj = url.split("?");
let params = Object.create(null)
if (arrObj.length > 1){
arrObj = arrObj[1].split("&");
arrObj.forEach(item=>{
item = item.split("=");
params[item[0]] = item[1]
})
}
return params;
}
// ?a=1&b=2&c=3 ==> {a: "1", b: "2", c: "3"}
32、downloadFile:base64数据导出文件,文件下载
function downloadFile(filename, data){
let DownloadLink = document.createElement('a');
40、Object.keys:返回一个由一个给定对象的自身可枚举属性组成的数组
Object.keys = Object.keys || function keys(object) {
if(object === null || object === undefined){
throw new TypeError('Cannot convert undefined or null to object');
}
let result = []
if(isArrayLike(object) || isPlainObject(object)){
for (let key in object) {
object.hasOwnProperty(key) && ( result.push(key) )
}
}
return result
}
41、Object.values:返回一个给定对象自身的所有可枚举属性值的数组
Object.values = Object.values || function values(object) {
if(object === null || object === undefined){
throw new TypeError('Cannot convert undefined or null to object');
}
let result = []
if(isArrayLike(object) || isPlainObject(object)){
for (let key in object) {
object.hasOwnProperty(key) && ( result.push(object[key]) )
}
}
return result
}
42、arr.fill:使用 value 值来填充 array,从start位置开始, 到end位置结束(但不包含end位置),返回原数组
Array.prototype.fill = Array.prototype.fill || function fill(value, start, end) {
let ctx = this
let length = ctx.length;
43、arr.includes:用来判断一个数组是否包含一个指定的值,如果是返回 true,否则false,可指定开始查询的位置
Array.prototype.includes = Array.prototype.includes || function includes(value, start){
let ctx = this
let length = ctx.length;