11-Apr-2023
.
Admin
Hi Guys,
In this blog, I will show you how to remove empty or null values from array using jquery. We will learn jquery remove empty or null values in array. i write small example of remove null from array in jquery.
Here i 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? - NiceSnippets.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 = ["Suresh", "", "Jayesh", null, "Rahul","", "Rohit",null];
var myArrayNew = myArray.filter(function (value) {
return value != null && value != "";
});
console.log(myArrayNew);
</script>
</body>
</html>
It will help you....
#Jquery