Iterate until queue is empty
while ( len > 0 ) { let temp = que [ 0 ] ; que . shift ( ) ; document . write ( temp . val + " " ) ; if ( temp . left != null ) que . push ( temp . left ) ; if ( temp . right != null ) que . push ( temp . right ) ; len -= 1 ; } document . write ( " " ) ; } document . write ( " " ) ; }