How to remove undefined value from jquery array?

By Hardik Savani March 12, 2016 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>

We are Recommending you