Snippet: js while(shift())

Written in JavaScript and posted on Dec 18, 2011 at 00:49 by apoc
   1  
   2  
   3  // does what you expect
   4  var a = ['foo', 'bar', 'baz'];
   5  var elm;
   6  while (elm = a.shift()) {
   7      console.log(elm);
   8  }
   9  
  10  
  11  // makes you sick:
  12  var a = ['foo', 'bar', '', 'baz'];
  13  var elm;
  14  while (elm = a.shift()) {
  15      console.log(elm);
  16  }