Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var myArray = [{'key': 'value'}, {'key': 'value1'}];
- for (var i = 0; i < myArray.length; i++)
- for (var i in myArray)
- for (var i = 0; i < a.length; i++)
- //do stuff with a[i]
- for (var key in o)
- //do stuff with o[key]
- for(name in object)
- {
- if (object.hasOwnProperty(name))
- {
- }
- }
- $(['a','b','c']).each(function() {
- alert(this);
- });
- //Outputs "a" then "b" then "c"
- for (var i = myArray.length-1; i >= 0; i--)
- for (var i = 0; i < myArray.length; i++)
- l = ''; for (m in obj) { l += m + ' => ' + obj[m] + 'n' } console.log(l);
- var array = [0, 1, 2, , , 5];
- for (var k in array) {
- // Not guaranteed by the language spec to iterate in order.
- alert(k); // Outputs 0, 1, 2, 5.
- // Behavior when loop body adds to the array is unclear.
- }
- for (var i = 0; i < array.length; ++i) {
- // Iterates in order.
- // i is a number, not a string.
- alert(i); // Outputs 0, 1, 2, 3, 4, 5
- // Behavior when loop body modifies array is clearer.
- }
- function foreach(o, f) {
- for(var i = 0; i < o.length; i++) { // simple for loop
- f(o[i], i); // execute a function and make the obj, objIndex available
- }
- }
- foreach(o, function(obj, i) { // for each obj in o
- alert(obj); // obj
- alert(i); // obj index
- /*
- say if you were dealing with an html element may be you have a collection of divs
- */
- if(typeof obj == 'object') {
- obj.style.marginLeft = '20px';
- }
- });
- for( var i=0,j=null; j=array[i++]; foo(j) );
Add Comment
Please, Sign In to add comment