Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 24th, 2012  |  syntax: None  |  size: 0.75 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. How to break from objx(data).each(function(item) iteration?
  2. var data= [{"field1": "0","field2": "2"},{"field1": "7","field2": "2"},{"field1": "1","field2": "5"}];
  3.        
  4. function iterate(){
  5.                 objx(data).each(function(item){
  6.                  if(item.field1 == "7"){
  7.                    //doing some job;
  8.                    return;
  9.                   }
  10.                  alert("after if is executed");// this alert coming inspite of giving
  11.                 });                            // return in if block
  12.              }
  13.        
  14. function iterate(){
  15.     objx(data).each(function(item){
  16.         if(item.field1 == "7"){
  17.             //to stop the loop here
  18.             return false; // here - will exit the each loop
  19.         }
  20.     });
  21. }
  22.        
  23. return false;