09 2020 档案

摘要:1.输出数组 let arr = [1,2,3] console.table(arr) 2.输出对象 let obj = { name:'zs',age:12 } console.table(obj) 3.输出指定的key,第二个参数传入一个key数组 // 第二个参数 let obj2 = [ { 阅读全文

posted @ 2020-09-29 01:48 猫头唔食鱼 阅读(836) 评论(0) 推荐(0) 编辑

摘要:在稀疏数组中,有些位置是没有元素的,例如 let b = [1,,3] 移除数组空缺: 1.使用filter let a = [1,,3] let arr = [] a.filter(v=>{ arr.push(v) }) console.log(arr);// [1,3] 2.使用forEach 阅读全文

posted @ 2020-09-29 01:19 猫头唔食鱼 阅读(140) 评论(0) 推荐(0) 编辑

摘要:稀疏数组含有空缺, 密集数组,每个位置都有元素(undefined也算是元素) 例如: // 1.稀疏数组 let ch = [,,3] // 2.密集数组 let ci = [undefined,undefined,3] 区别: // 3.区别: // (1) in 操作符找index conso 阅读全文

posted @ 2020-09-28 02:47 猫头唔食鱼 阅读(249) 评论(0) 推荐(0) 编辑

摘要:清除共享数组,需要把数组长度设置为0,而不是把数组设置为空数组 正确: // 清除共享数组 let cd = [1,2,3] let ce = cd cd.length = 0 console.log(cd,ce); // [] ,[] 错误: let cf = [1,2,3] let cg = c 阅读全文

posted @ 2020-09-28 02:32 猫头唔食鱼 阅读(139) 评论(0) 推荐(0) 编辑

摘要:1.toString 不适用于undefined 和 Null 2. value + '' 3. String(value) 4.JSON.stringify() console.log(JSON.stringify(5)); // '5' console.log(JSON.stringify(Na 阅读全文

posted @ 2020-09-28 00:59 猫头唔食鱼 阅读(686) 评论(0) 推荐(0) 编辑

摘要:关于NaN的一些操作: 1.isNaN(n) let a = NaN console.log(isNaN(a)) // true 2.Object.is(n) let a = NaN console.log(Object.is(a,NaN)) // true 3.封装成方法:NaN连自己本身都不相等 阅读全文

posted @ 2020-09-28 00:18 猫头唔食鱼 阅读(2630) 评论(0) 推荐(0) 编辑

摘要:// new Boolean(false) 为真值 console.log(Boolean(new Boolean(false)) true); // true 阅读全文

posted @ 2020-09-27 23:56 猫头唔食鱼 阅读(369) 评论(0) 推荐(0) 编辑

摘要:1. Boolean(value) let bn = 3 console.log(Boolean(bn)); // true 2.value ? true :false console.log(bn?true :false); // true 3.!!value console.log(!!bn); 阅读全文

posted @ 2020-09-27 22:35 猫头唔食鱼 阅读(1077) 评论(0) 推荐(0) 编辑

摘要:函数柯里化是指把函数多个参数,转化成一个参数传入。 一个简单例子 let add = (a, b) => a + b console.log(add(2, 3)); // 函数柯里化 let currying = (a) => (b) => a + b console.log(currying(2) 阅读全文

posted @ 2020-09-27 22:02 猫头唔食鱼 阅读(758) 评论(0) 推荐(0) 编辑

摘要:let arr = [1,2,3] let arr2 = [3,1,2] let arr3 = [1,2,2] let arr4 = ['1',2,3] let compare = (arr,arr2) => JSON.stringify(arr.sort()) JSON.stringify(arr 阅读全文

posted @ 2020-09-22 21:54 猫头唔食鱼 阅读(530) 评论(0) 推荐(0) 编辑

摘要:1.promise resolve之后还会继续执行,如果不想resolve之后继续执行,可以加上return let p = ()=>{ return new Promise(resolve=>{ setTimeout(()=>{ resolve('data') console.log('会继续执行 阅读全文

posted @ 2020-09-22 21:47 猫头唔食鱼 阅读(158) 评论(0) 推荐(0) 编辑

摘要:1.数组去重 var unique = (arr) => [...new Set(arr)] console.log(unique([1, 2, 3, 1])); 2.set转为数组 // Array.from(set)和展开set作用一样,都是把set转为数组 var set2 = new Set 阅读全文

posted @ 2020-09-22 03:13 猫头唔食鱼 阅读(156) 评论(0) 推荐(0) 编辑

摘要:用法1:替换数组的值 // 用法1:替换数组的值 let a = [1,2,3],b = [4,5] console.log( Object.assign(a,b)); // 后面的值覆盖前面的值,[4,5,3] 用法2:为对象添加属性 下面是es5的写法:this.xxx =xxx // es5的 阅读全文

posted @ 2020-09-22 02:37 猫头唔食鱼 阅读(383) 评论(0) 推荐(0) 编辑

摘要:// 假值转换为0 let toZero = (arr)=>{ return arr.map(v=>v||0) } let c = [1,2,3,0,false,null,undefined,NaN,''] console.log(toZero(c)); // [1, 2, 3, 0, 0, 0, 阅读全文

posted @ 2020-09-22 00:31 猫头唔食鱼 阅读(214) 评论(0) 推荐(0) 编辑

摘要:方法一:使用indexOf是不能找到数组里的NaN的 ,正确用法是,includes var arr10 = [1, NaN, 2] console.log(arr10.indexOf(NaN)); // -1 用这个方法找数组里的NaN是找不到的 // includes找出数组里的NaN cons 阅读全文

posted @ 2020-09-21 21:49 猫头唔食鱼 阅读(894) 评论(0) 推荐(0) 编辑

摘要:Array.from的一个特性:所有具有length属性的对象,并且key是数字,都能被Array.from转为数组 // 用法一:对象转数组 // example 1: let obj = {0:'a',1:'b',2:'c',length:3} console.log( Array.from(o 阅读全文

posted @ 2020-09-21 21:46 猫头唔食鱼 阅读(637) 评论(0) 推荐(0) 编辑

摘要:先看一个错误的例子: arr.forEach((v,i)=>{ if(v>2){ arr.splice(i,1) } }) console.log(arr); // [1,2,4] 删除数组中大于2的元素,但是得到[1,2,4] 正确的写法: 用for循环,注意for的条件 var arr = [1 阅读全文

posted @ 2020-09-07 15:17 猫头唔食鱼 阅读(870) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示