<!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>
var students = [{
studentName: "小明",
age: 16,
school: "清华",
}, {
studentName: "小黑",
age: 17,
school: "北大"
}, {
studentName: "小红",
age: 18,
school: "浙大"
}, {
studentName: "小红",
age: 15,
school: "浙大"
}]
aa()
console.log('========================')
bb()
function aa() {
let results = students.filter((item, i) => {
return item.age % 2 == 0
})
console.log(results) //数组
// Array(2)
// 0: {studentName: "小明", age: 16, school: "清华"}
// 1: {studentName: "小红", age: 18, school: "浙大"}
// length: 2
// __proto__: Array(0)
}
</script>
</body>
</html>
return判断并返回数组
最新推荐文章于 2022-06-23 16:48:09 发布