首页 > 试题广场 >

var arra...

[问答题]

    var array = ["first","second","third","fourth"];
    
    // 执行到第3次,结束循环
    array.forEach(function(item,index){
        if (item == "third") {
           //等于third时跳出这个循环,如何实现
        }
        alert(item);// first,sencond
    });


throw new Error("跳出循环")
发表于 2021-04-14 16:22:56 回复(0)
    var array = ["first","second","third","fourth"];
    
    // 执行到第3次,结束循环
    array.forEach(function(item,index){
        if (item == "third") {
            return
           //等于third时跳出这个循环,如何实现
        }
        alert(item);// first,sencond
    });
} 

发表于 2022-07-07 18:55:13 回复(0)
 var array = ["first","second","third","fourth"];
    
    try{
        // 执行到第3次,结束循环
        array.forEach(function(item,index){
            if (item == "third") {
               //等于third时跳出这个循环,如何实现
                throw new Error('');
            }
            alert(item);// first,sencond
        });
    }catch(e){
        
    }

发表于 2022-05-09 15:44:38 回复(0)
    var array = ["first","second","third","fourth"];
    
    // 执行到第3次,结束循环
    try{
        array.forEach(function(item,index){
        if (item == "third") {
           //等于third时跳出这个循环,如何实现
            new Error('跳出');
        }
        alert(item);// first,sencond
    });
    }catch(err){
        
    }


发表于 2022-01-12 21:47:37 回复(0)
return ;
发表于 2021-10-05 10:42:19 回复(0)