JavaScript Array filter() 方法
var ages = [32, 33, 16, 40]; function checkAdult(age,index,array) {
return age >= 18;
} function myFunction() {
document.getElementById("demo").innerHTML = ages.filter(checkAdult);
}
输出结果为:
32,33,40
2023-01-29 19:28:11
var ages = [32, 33, 16, 40]; function checkAdult(age,index,array) {
return age >= 18;
} function myFunction() {
document.getElementById("demo").innerHTML = ages.filter(checkAdult);
}
输出结果为: