foreEach 跳出循环

const arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
const _ = require('lodash');

let outArr = [];
try {
    arr.forEach(obj => {
        console.log(obj);
        if (obj < 3) {
            outArr.push(obj);
        } else {
            throw new Error('brack');
        }
    });
} catch (err) {
}

方法一: try catch

 

 

posted @ 2018-10-11 11:02  秋野春上飞  阅读(437)  评论(0编辑  收藏  举报