ItSolutionStuff.com

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

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

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

JQuery Redirect to Another Page After 5 Seconds Example

Read Now →

How to Set Maxlength for Textarea in Javascript?

Read Now →

JQuery Add Remove Input Fields Dynamically Example

Read Now →

JQuery Select Box with Search Option using Chosen Plugin

Read Now →

Preview an image before Upload using jQuery Example

Read Now →

How to Get First Element of Array in Javascript?

Read Now →

How to Get Last Element of Array in Javascript?

Read Now →

How to Get Max Attribute Value in JQuery?

Read Now →

How to Remove Query String from URL using JQuery?

Read Now →

Automatically Scroll to Bottom of Div JQuery Example

Read Now →

How to Check Undefined, Empty and Null in JQuery?

Read Now →

How to Convert Line Breaks to br in jQuery ?

Read Now →

How to Check Object is Empty or Not in JQuery?

Read Now →

Autocomplete with Images and Custom HTML Code in Jquery UI?

Read Now →