Web端 es6(基础五) 数组扩展
2018-02-03 13:29
363 查看
常用
转换为数字 Arrayof
对每个元素进行操作
fill 批量替换
数组遍历
数组浅复制 copyWithin
数组位置查找 find
数组过滤
转换为数字 Arrayof
对每个元素进行操作
fill 批量替换
数组遍历
数组浅复制 copyWithin
数组位置查找 find
数组过滤
常用
转换为数字 Array.of
let numbers = Array.of(1,2,3,4); console. 4000 log(numbers) // 输出结果 (4) [1, 2, 3, 4]
对每个元素进行操作
//对每个元素进行操作 let array = Array.from([1,2,3],(item) =>{ return item * 2 }) console.log(array) // 输出结果 (3) [2, 4, 6]
fill 批量替换
fill (替换的数值,起始位置,结束位置)console.log([1,'hello',undefined].fill(7)) console.log(['a','b','c','d','e','f','g'].fill(7,1,3)) // 输出结果 (3) [7, 7, 7] (7) ["a", 7, 7, "d", "e", "f", "g"]
数组遍历
for (let index of ['a','b','c']){ console.log(index) } // 输出结果 abc for (let index of ['a','b','c'].keys()){ console.log(index) } // 输出结果 0 1 2 for (let [index,value] of ['a','b','c'].entries()){ console.log(index,value) } // 输出结果 0 "a" 1 "b" 2 "c"
数组浅复制 copyWithin
方法浅复制数组的一部分到同一数组中的另一个位置,并返回它,而不修改其大小。console.log([33,38,39,40,50].copyWithin(0,3,4)) // 输出结果 (5) [40, 38, 39, 40, 50]
数组位置查找 find
// 输出查找 值 let result = [1,2,3,4,5,6].find((item)=>{ return item > 3; }) console.log(result) // 输出结果 4 // 查找下标 let result = [1,2,3,4,5,6].findIndex((item)=>{ return item > 3; }) console.log(`index=${result}`) // 输出结果 index = 3
数组过滤
let result = [1,2,3,4,5,6].filter((item)=>{ return item > 3; }) console.log(result) // 输出结果 (3) [4, 5, 6]
相关文章推荐
- Web端 es6(基础七) 对象扩展
- Web端 es6(基础四) 数值扩展 Number
- Web端 es6(基础六) 函数扩展
- Es6 学习笔记(一)数组扩展
- JS中数组的常用方法(包含es6扩展)
- ES6-数组的扩展-数组实例的fill()
- JS中数组的常用方法(包含es6扩展)
- es6 数组扩展方法
- Web前端从入门到放弃(js数组基础和数组方法的各种使用)
- ES6数组的扩展
- ES6 数组扩展
- 从零开始学 Web 之 ES6(五)ES6基础语法三
- ES6 之 数组扩展
- Web端 es6(基础十五) Decorators
- ES6 - Note3:数组、对象与函数的扩展
- ES6 数组扩展
- webpack打包,es6语法报错,解决方案(包括es6扩展运算符报错)
- ES6数组扩展知识(ECMAScript 6 入门笔记)
- ECMAScript6(ES6)标准之数组Array扩展方法
- ES6-数组的扩展-Array.of()