foreach equivalent of php in jquery?

前端 未结 5 1754
再見小時候
再見小時候 2020-12-31 06:58

Is there a foreach code in JQuery as in PHP? I have a code in php,like

       
if(\"

        
5条回答
  •  生来不讨喜
    2020-12-31 07:24

    The $.each function is similar.

    It allows you to iterate arrays using a callback function where you have access to each item:

    var arr = [ "one", "two", "three", "four", "five" ];
    
    
    $.each(arr, function(index, value) {
      // work with value
    });
    

    Maybe is useful to know, if you want to break the loop, you can do it with return false; or if you want to skip only one iteration (continue), you return true;

提交回复
热议问题