数组方法
閉丄眼聆厛倖輻
这个作者很懒,什么都没留下…
展开
-
数组合并concat,数组切片slice,event,循环遍历:map,forEach,筛选过滤:filter,查找:find,findIndex,reduce(),
数组合并let arr = [1, 2, 3, 4, 5, 6, 7];const result = arr.concat([4, 5, 6], 7, 8);console.log(result);数组剪切:slice(index1,index2)取数组下标[index1,index2),index1的下标取,index2小标对应的数据不取 let arr = [1, 2, 3, 4, 5, 6, 7]; let result = arr.slice(1, 5);//[2,3,4,5原创 2021-08-02 20:27:17 · 135 阅读 · 0 评论 -
数组去重,数组对象去重
数组去重,运用ES6语法let arr = [1,2,3,4,5,6,1,2,3]console.log([...new Set(arr)]);// [1, 2, 3, 4, 5, 6]数组对象去重,通过对象中的值去重,可选值,实际是根据reduce let arr = [ { id: 0, name: "猴子" }, { id: 1, name: "李白" }, { id: 2, name: "小乔" }, { id: 3, name: "貂原创 2021-07-28 16:57:05 · 58 阅读 · 0 评论 -
ES6的filter
数组的处理:filterfilter只会返回新数组,不会改变原数组 let number = [1, 2, 3, 4]; let newNumber = number.filter((item) => { return item > 2; }); console.log("原数组", number); console.log('新数组',newNumber);结果: 原数组 (4) [1, 2, 3, 4] 新数组 (2) [3, 4]或者在vue中定义原创 2021-07-09 10:08:17 · 183 阅读 · 0 评论