Use if statement to check undefined values - Javascript Data Type

Javascript examples for Data Type:undefined

Description

Use if statement to check undefined values

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=( function() {/*from w  ww. ja  va 2 s . co  m*/
var undef;
var arr = [1,2, undef, 3, 4, undef,'',undefined,"",' '];
var temp = [];
for (var i=0; i < arr.length; i++) {
    if ( arr[i] ) {
        temp.push(arr[i])
    }
}
console.log(temp);
arr = temp;
temp = null;
console.log(arr);
    });

      </script> 
   </head> 
   <body>  
   </body>
</html>

Related Tutorials