We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
No description provided.
The text was updated successfully, but these errors were encountered:
实例
返回一个数组,数组中元素为原始数组的平方根:
var numbers = [4, 9, 16, 25]; function myFunction() { x = document.getElementById("demo") x.innerHTML = numbers.map(Math.sqrt); }
输出结果为:
2,3,4,5
定义和用法
map() 方法返回一个新数组,数组中的元素为原始数组元素调用函数处理后的值。
map()
map() 方法按照原始数组元素顺序依次处理元素。
注意: map() 不会对空数组进行检测。
注意: map() 不会改变原始数组。
接口数据映射
从接口得到数据 res:
res
let r = res.map(item => { return { title: item.name, sex: item.sex === 1? '男':item.sex === 0?'女':'保密', age: item.age, avatar: item.img } })
也可以省略return:
return
const users=res.items.map(item => ({ url: item.html_url, img: item.avatar_url, name: item.login, }) );
Sorry, something went wrong.
No branches or pull requests
No description provided.
The text was updated successfully, but these errors were encountered: