美文网首页
相关代码总结

相关代码总结

作者: 卓然凌昭 | 来源:发表于2019-01-13 23:59 被阅读0次

1.数组去重

function unique(arr){
    return arr.filter(function(item,index){
        return arr.indexOf(item) == index;
  })
}

2.深拷贝数组或者对象

function deepClone(a){
  
  var newObj = Object.prototype.toString.call(a) === "[object Array]"?[]:{};
  for (var i in a){
    if (a.hasOwnPropertyof(i)){
      newObj[i] = typeof a[i] =="object"?deepClone(a[i]):a[i];
    }
  }
  return a;
}

相关文章

网友评论

      本文标题:相关代码总结

      本文链接:https://www.haomeiwen.com/subject/bserdqtx.html