Each function and array : each « jQuery « JavaScript Tutorial






<html>
  <head>
    <script type="text/javascript" src="js/jquery-1.3.2.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){

      var anArray = ['one','two','three',4];
      var anObject = {one:1, two:2, three:3};

      $.each(anArray,function(n,value){
        document.write('['+n+']='+value);
      });

      $.each(anObject,function(n,value){
        document.write('['+n+']='+value);
      });
        });
    </script>

  </head>
  <body>
    <body>
        <p id="followMe">Follow me!</p>
    </body>
</html>








30.32.each
30.32.1.Loop through each tag
30.32.2.each function callback
30.32.3.Each span tag
30.32.4.For each array element
30.32.5.For each function with index and value
30.32.6.Use Each Function To loop through Selected Item
30.32.7.Each function and array
30.32.8.Each function and map array
30.32.9.Use 'return' to break out of each() loops early.
30.32.10.Get each loop index
30.32.11.Use foreach to create li
30.32.12.Append value with each function
30.32.13.Return true as continue statement
30.32.14.Use each function to add class
30.32.15.Hard code value into each function