js 数组API之forEach、map的用法
2017-12-18 15:05
543 查看
forEach语法:
arr.forEach(function(value, index, array){……})
实例:
// forEach var arr = [1,2,3,4,5]; arr.forEach(function(value, index, array){ array[index] *= 2; }); console.log(arr); //[2,4,6,8,10]
map语法:
var newArr = arr.map(function(value, index, array){return 要放入新数组的值})
实例:
// map var arr = [1,2,3,4,5]; var newArr = arr.map(function(value, index, array){ return value * 2; }); console.log(arr); // [1,2,3,4,5] console.log(newArr); // [2,4,6,8,10]
相关文章推荐
- js 数组API之filter的用法
- Js 数组——filter()、map()、some()、every()、forEach()、lastIndexOf()、indexOf()
- js中数组过滤、遍历、迭代every、some、filter、map、forEach、reduce、reduceRight
- JS中 map, filter, some, every, forEach, for in, for of 用法总结
- JS数组filter()、map()、some()、every()、forEach()、lastIndexOf()、indexOf()实例
- JS中 map, filter, some, every, forEach, for in, for of 用法总结
- js数组的遍历方法filter()、map()、some()、every()、forEach()、lastIndexOf()、indexOf()
- 浅析JS中的 map, filter, some, every, forEach, for in, for of 用法总结
- Js 数组方法:filter()、map()、some()、every()、forEach()、indexOf()、lastIndexOf()、
- js 数组 map() 基本用法
- ES6数组新增方法forEach、map、filter、find、every、some、reduce的用法
- JS中 map, filter, some, every, forEach, for in, for of 用法总结
- JS数组中every(),filter(),forEach(),map(),some()方法学习笔记!
- js数组遍历some,foreach,map,filter,every对比
- vue之mapMutaions的使用 && vuex中 action 用法示例 && api.js的使用
- JS数组方法总结shift()、unshift()、pop()、push()、concat()、splice()、filter()、map()、some()、every()、forEach()等方法
- JS 语言数组中 API 和 用法
- js数组中forEach/some/every/map/filter/reduce的区别
- JS中的 map, filter, some, every, forEach, for...in, for...of 用法总结
- JS map forEach filter indexOf 用法