Check variables and add them to comma separated list - Javascript Array

Javascript examples for Array:filter

Description

Check variables and add them to comma separated list

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. j ava2  s  .  c o m
a = '';
b = 'second';
c = '';
d = 'fourth';
var arr=[];
arr.push(a)
arr.push(b)
arr.push(c)
arr.push(d)
var newarr = arr.filter(function(v){
  return v != '';
});
newarr = newarr.join(',');
console.log(newarr);
    }

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

Related Tutorials