How to Remove Empty or Null Values from Array in JQuery?

By Hardik Savani July 3, 2023 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...

Shares