<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>es5数组方法</title>
</head>
<body>
<script>
var arr = [
{
"name":"xiaoming",
"age":"20"
},
{
"name":"xiaoma",
"age":"22"
},
{
"name":"xiaowang",
"age":"25"
}
];
arr.forEach(function(value,index){
console.log(value.name)
})//forEach方法
var studentName = arr.map(function(user){
return user.name;
});//map方法
console.log(studentName)
console.log(studentName.join(", "))
//map方法和forEach方法类似,只不过map有返回值
</script>
</body>
</html>
es5 forEach 和 map 方法使用
最新推荐文章于 2024-04-05 00:22:19 发布