JS基础
文章平均质量分 66
巧克力味儿的Sherry
其他博客名称:公主是个元气少女
展开
-
JS基础(3)——手写数组原型函数 之 改变原数组(push,pop,shift,unshift,reverse,fill)
JS基础(2)——手写数组原型函数 之 不改变原数组(push,pop,shift,unshift,reverse,fill)11、Array.prototype.push参数 element1,…,elementN返回值 新length可通过call/apply用于类数组push 方法根据 length 属性来决定从哪里开始插入给定的值。如果 length 不能被转成一个数值,则插入的元素索引为 0,包括 length 不存在时。当 length 不存在时,将会创建它。Array.protot原创 2021-07-12 16:07:30 · 787 阅读 · 0 评论 -
JS基础(2)——手写数组原型函数 之 不改变原数组(filter,find,findIndex,some,every,map,forEach,reduce)
JS基础(2)——手写数组原型函数 之 不改变原数组(filter,find,findIndex,some,every,map,forEach,reduce)1、模板Array.prototype.myFunction = function(callback, thisArg) { if(this == undefined){ throw new TypeError('this is null or not defined'); } if(typeof callback !== 'f原创 2021-07-12 11:51:12 · 179 阅读 · 0 评论 -
JS基础(1)——数组扁平化、去重、类数组转化为数组
JS基础(1)——数组扁平化、去重、类数组转化为数组一、数组扁平化const arr1 = [1, [2, [3, [4, 5]]], 6];// => [1, 2, 3, 4, 5, 6]1.ES6的flat()const res1_1 = arr1.flat(Infinity);Array.prototype.flat() 特性总结:用于将嵌套的数组扁平化,变成一维的数组。该方法返回一个新数组,对原数据没有影响。不传参数时,默认扁平化一层,可以传入一个整数,表示想要扁平化的层原创 2021-07-07 19:55:42 · 213 阅读 · 0 评论