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())
        }
posted @ 2012-12-27 17:50  不要说话,用心听  阅读(410)  评论(0编辑  收藏  举报