Javascript examples for Data Type:undefined
Clear and remove undefined values from an array
<html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <script type="text/javascript"> window.onload=( function() {//from w w w . j a va 2s . 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>