- 判断object
- 判断undefined
- 判断非undefined
- 转换成字符串
- 数组转换成对象
判断object
function isObject(obj){
return obj !== null && typeof obj==='object'
}
判断undefined
function isUndef(v){
return v===undefined || v===null
}
判断非undefined
function isUndef(v){
return v!==undefined && v!==null
}
转换成字符串
function toString(val){
return val == null? '': typeof val==='object'? JSON.stringify(val): String(val);
}
数组转换成对象
function toObject(arr){
var res={};
arr.forEach((item,index)=>{
res[index]=item;
});
return res
}