How to remove undefined value from jquery array?

By Hardik Savani | March 12, 2016 | | 38562 Viewer | Category : Javascript jQuery


If you have jquery or javascript array with lots of undefined value and you want to remove all undefined value from array. you can remove undefined items from your array without using each loop you have to just use filter, I would like give the example how to remove undefined element from javascript array. so, let's see bellow example.

<script type="text/javascript">

var obj = ['3','3','5',undefined,'hi'];

obj = obj.filter(function(e){return e});

console.log(obj);

</script>



Hardik Savani
My name is Hardik Savani. I'm a full-stack developer, entrepreneur and owner of Aatman Infotech. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.
***Do you want me hire for your Project Work? Then Contact US.