1. 程式人生 > >js中for、$.each、 forEach,while的對比和break,continue使用

js中for、$.each、 forEach,while的對比和break,continue使用

js中的迴圈

for 原始 但有一點繁瑣,
$.each jQ提供的for函式
forEach es5提供的方法

跳出迴圈

for => break;
$.each => return false;
forEach 沒有

跳過迴圈

for =>continue;
$.each => return true;/return;
forEach => return /* any */;

while可以做死迴圈然後 用break跳出來