How to Remove Empty or Null Values from Array in 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
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. 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, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- JQuery Redirect to Another Page After 5 Seconds Example
- How to Set Maxlength for Textarea in Javascript?
- JQuery Add Remove Input Fields Dynamically Example
- JQuery Select Box with Search Option using Chosen Plugin
- Preview an image before Upload using jQuery Example
- How to Get First Element of Array in Javascript?
- How to Get Last Element of Array in Javascript?
- How to Get Max Attribute Value in JQuery?
- How to Remove Query String from URL using JQuery?
- Automatically Scroll to Bottom of Div JQuery Example
- How to Check Undefined, Empty and Null in JQuery?
- How to Convert Line Breaks to br in jQuery ?
- How to Check Object is Empty or Not in JQuery?
- Autocomplete with Images and Custom HTML Code in Jquery UI?