Breaking out of a PrototypeJS .each() loop

前端 未结 4 1379
难免孤独
难免孤独 2021-02-05 09:52

In this very contrived example, I have an array with 3 elements that I\'m looping over using the .each() method.

var vals = $w(\'foo bar baz\'); 

vals.each( func         


        
4条回答
  •  旧时难觅i
    2021-02-05 10:42

    Based on the documentation for .each() that you linked to, you should use a throw $break; statement, this should cause further iterations to cease.

    Simply returning will cause the iterator to continue to the next one.

提交回复
热议问题