Jquery - How to remove empty or null values from array?

By Hardik Savani | January 29, 2019 | | 14469 Viewer | Category : Javascript jQuery


Hey Developer,

Are you looking for remove empty value or null value from array in javascript? than you are a right place. i will show you how to remove empty values from string array in jquery. i write small example of remove null from array in jquery.

we will use jquery array filter function for remove empty or null value. in filter function we will return values if string value is not empty or null value.

var myArrayNew = myArray.filter(function (el) {

return el != null && el != "";

});

Here you can see full example of delete empty or null values from array in jquery. So just check bellow full example for your help.

Example:

<!DOCTYPE html>

<html>

<head>

<title>Jquery - How to remove empty or null values from array? - ItSolutionstuff.com</title>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

</head>

<body>

<script type="text/javascript">

var myArray = ["Hardik", "Paresh", "Sagar", "", "Rahul", null, "Kiran"];

var myArrayNew = myArray.filter(function (el) {

return el != null && el != "";

});

console.log(myArrayNew);

</script>

</body>

</html>

I hope it can help you...



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.


We are Recommending you: