1、判断简化:

if(a== 1  ||  a == undefined  a == null  ||  a==15){   ...

}

可转化为:if( [1, undefined, null, 15].includes(a) ){...}

2、清空数组array.length = 0

3、但是使用concat()方法时,如果需要合并的数组很大,那么concat() 函数会在创建单独的新数组时消耗大量内存。这时可以使用以下方法来实现数组的合并:Array.prototype.push.apply(start, end)

4、输出简化:

const c = console.log.bind(document)

 c("hello world")

5、获取url地址中的参数: let type = new URLSearchParams(location.search).get('type');

6、小数取整:~~1.22  ----->1

posted on 2022-01-12 17:46  热心市民宗某§  阅读(30)  评论(0)    收藏  举报