每天get几个JavaScript小技巧(二)

判断两个数组是否相等
const isArray = function(arr) {
  return Object.prototype.toString.call(arr) === '[object Array]'
}
时间与时间戳转换
const stamp = {
  getTime: function(time) {  //时间转10位时间戳
    let date = time ? new Date(time) : new Date()
    return Math.round(date.getTime() / 1000)
  },
  timeToStr: function(time, fmt) { //10位时间戳转时间
    return new Date(time * 1000).pattern(fmt || 'yy-MM-dd')
  }
}
判断是否为微信
const isWx = function() {
  let ua = window.navigator.userAgent.toLowerCase()
  if(ua.match(/MicroMessenger/i) === 'microMessenger') {
    return true
  }
  return false
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。