使用try catch可以跳出forEach


        var item = null;
        try {
            arr.forEach(function (curItem, i) {
                if (curItem.id == id) {
                    item = curItem;
                    throw Error();
                }
            })
        } catch (e) {
        }
       console.log('跳出来了')
    

作者 译文

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注