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
var ages = [32, 33, 16, 40]; function checkAdult(age,index,array) { return age >= 18; } function myFunction() { document.getElementById("demo").innerHTML = ages.filter(checkAdult); }
输出结果为: