<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
console.log("map属性的使用");
let arr = [1,2,3,4];
var map = arr.map(function(currentValue){
return currentValue*2;
});
console.log("原数组值不变");
console.log(arr);
console.log("map函数后得到的数组");
console.log(map);
let people = [{name:"zs",age:1},{name:"ls",age:2},{name:"ww",age:3},{name:"zl",age:4}];
var peopleMap = people.map(function(currentValue){
currentValue.age = currentValue.age*2
return currentValue;
});
console.log("原数组值不变");
console.log(people);
console.log("map函数后得到的数组");
console.log(peopleMap);
</script>
<script>
console.log("reduce属性的使用");
let arrs = [1,2,3,4];
var rs = arrs.reduce(function(accumulator, currentValue){
return accumulator+currentValue;
});
console.log("原数组值不变");
console.log(arrs);
console.log("reduce函数后得到的值为数组所有元素的和");
console.log(rs);
</script>
</body>
</html>