map不是地图,而是指映射

例 求数组值平方

var arr = ['1', '2', '3']
var r = arr.map(item => {
    return  item*item
})
console.log(r)
//输出
[1, 4, 9]

例 获得数组中特定属性的值

var user = [
    { name: '杨幂','phone': '10000000000'},
    { name: '佟丽娅','phone': '20000000000'},
    { name: '张俪','phone': '30000000000'},
]
var phones = user.map(user =>{
    return user.phone
})
console.log(phones.join(','))
//输出
10000000000,20000000000,30000000000

你的闲暇往往定你的终身

标签云

友情链接