- map会返回处理后结果
//顺便学习Object.keys
let person = {name:"张三",age:25,address:"深圳",getName:function(){}}
res = Object.keys(person).map((key)=>{
person[key] // 获取到属性对应的值,做一些处理
// console.log(person[key])
return person[key]
})
console.log(res) //[ '张三', 25, '深圳', [Function: getName] ]
res = Object.keys(person).forEach((key)=>{
person[key]
// console.log(person[key])
return person[key] //foreach不会返回
})
console.log(res) //undefined
- forEach
var numbers = [1, 2, 3];
numbers.forEach(x => console.log(x)); //ES6 的 => 语法让匿名函数更简洁【x => xxx 等于 function (x) {xxx}】
// 同等于
numbers.forEach(function (x) {
console.log(x);
});