JavaScript Array some() 方法

 例子1,无thisValue参数:
<script>
var ages = [3, 10, 18, 20];
function checkAdult(age) {
    return age >= 18;
}
function myFunction() {
    document.getElementById("demo").innerHTML = ages.some(checkAdult);
}
</script>

The results show TRUE, the presence of greater than 20 18

Examples 2, thisValue parameters:
<Script>
var AGEs = [. 3, 10, 18 is, 20 is];
function checkAdult (Age) {

alert (this); thisValue active position, this is the pop 7 is the second parameter is set som.
    Age return> = 18 is;
}
function myFunction () {
    document.getElementById ( "Demo") = the innerHTML ages.some (checkAdult,. 7);.
}
</ Script>

Screenshot operating results:

Each element will pop up once a traverse 7, the last display true

发布了30 篇原创文章 · 获赞 17 · 访问量 7万+

Guess you like

Origin blog.csdn.net/sunboylife/article/details/104702657