美文网首页
有用的javaScript技巧

有用的javaScript技巧

作者: Mr丶何 | 来源:发表于2019-08-01 11:34 被阅读0次

    数组去重

    var j = [...new Set([1,2,2,4])];     // [1,2,4]

    判断对象和数组方法

    Object.prototype.toString.call({}) 返回字符串的 '[object Object]'

    Object.prototype.toString.call([]) 返回字符串的 '[object Array]'

    对象是否包含某个属性

    Obj.hasOwnProperty('name')

    过滤空值

    let res = [1,2,0,undefined,null,false,''].filter(Boolean);   >>1,2

    合并对象

    const person = { a:1 };

    const tools = { b: 2 };

    const attributes = { c:3 };

    const summary = {...person, ...tools, ...attributes};   >> {a:1, b:2, c:3}

    相关文章

      网友评论

          本文标题:有用的javaScript技巧

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