Javascript examples for Array:filter
Check variables and add them to comma separated list
<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>