Js function package used

  • Judgment object
  • Judgment undefined
  • Non-undefined judge
  • Into a string
  • Converted into an array of objects

 

Judgment object

function isObject(obj){
    return obj !== null && typeof obj==='object'
}

Judgment undefined

function isUndef(v){
    return v===undefined || v===null
}

Non-undefined judge

function isUndef(v){
    return v!==undefined && v!==null
}

Into a string

function toString(val){
  return val == null? '': typeof val==='object'? JSON.stringify(val): String(val);
}

Converted into an array of objects

function toObject(arr){
  var res={};
  arr.forEach((item,index)=>{
    res[index]=item;
  });
  return res
}

 

Guess you like

Origin www.cnblogs.com/jingouli/p/11811201.html
Recommended