摘要:
let res = 'aabbaaaaccdeee'.replace(/(.)\1*/g, '$1'); console.log(res)// abacde 阅读全文
摘要:
方法1 let obj1 = {} let obj2 = {a:1} function func(obj) { for(let key in obj) return false return true } console.log(func(obj1)) console.log(func(obj2)) 阅读全文
摘要:
const number = test || 0; 当test值为truthy时,取test的值,否则取0。这样可以避免number被赋为NaN、null、undefined、false等值。 const number = test && test.value; 当test值为truthy时,再去取 阅读全文
摘要:
const arr1 = [1,2,3, 3, 2] const getUniqueArray = arr => [...new Set( arr)]; let res = getUniqueArray(arr1) console.log(res) 阅读全文
摘要:
(function () { console.log('自执行函数1'); })(); (function () { console.log('自执行函数2'); }()); !function () { console.log('自执行函数3'); }(); + function () { con 阅读全文
摘要:
方法1 let arr1 = [1,2,3] let arr2 = arr1 arr1 = [] console.log(arr1,arr2) // [] [1,2,3] 方法2 const arr1 = [1,2,3] const arr2 = arr1 arr1.length = 0 conso 阅读全文
摘要:
let arr = [1,2,3,4,5] let max = Math.max.apply(Array, arr) let min = Math.min.apply(Array, arr) console.log(max, min) 阅读全文
摘要:
function shuffle(arr) { for(let i = 0; i < arr.length; i++){ let randomIndex = Math.floor(Math.random() * (i + 1)) let item = arr[randomIndex] arr[ran 阅读全文
摘要:
function uniqueArr(arr) { return [...new Set(arr.flat(Infinity))] } let str = 'abccccccdddww' console.log(uniqueArr(str.split(''))) let arr = [1, [1, 阅读全文
摘要:
let str = 'abccccccdddww' function getType(variable) { return Object.prototype.toString.call(variable).replace(/\[object\s|\]/g, '') } console.log(get 阅读全文