Method 1 – Using For Loop
Sometimes you may like to use older ways that is easy to use. This is simple c programming like for loop, easy to use and works perfect.1 2 3 4 5 6 7 8 9 | <script type="text/javascript"> var index; var arr = ["Jan", "Feb", "Mar", "Apr"]; for (index = 0; index < arr.length; ++index) { console.log(arr[index]); } </script> |
Method 2 – Using forEach
The forEach function calls callbackfn function one time for each element present in the array, in ascending index order. This is also useful for navigating through an array. JavaScript forEach() function is also useful for navigating though array elements.1 2 3 4 5 6 7 8 | <script type="text/javascript"> var arr = ["Jan", "Feb", "Mar", "Apr"]; arr.forEach(function(entry) { console.log(entry); }); </script> |
Comments
Post a Comment