JS forEach和Jquery each
$(function () { var sss = [3, 2, 1, 4, 5]; $.each(sss, function (i, o) { if (o > 1) { document.writeln(o); } else { return false; //相当于break return;//相当于continue } }) })
ECMAScript5中添加的forEach如果要提前终止需要用包括在try catch中
var sss = [3, 2, 1, 4, 5]; try { sss.forEach(function (o) { if (o > 1) { document.writeln(o); } else { throw "asdasd"; } }) } catch (e) { document.writeln(e.toString()) }