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
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) { }
转载于:https://www.cnblogs.com/calvin-dong/p/9771278.html