ItSolutionStuff.com

How to Remove Element from Array in JQuery?

By Hardik Savani • July 20, 2023
jQuery

Hi Dev,

Today, in this example, we will learn how to delete array element by value in jquery. we can easily remove array element by value in jquery. we will see two example of jquery remove value from array by value.

If you may require to removing array element by value then you are a right place. i will give you two way to delete array element by value in jquery. first we will use splice() and inArray() for remove key value by value. Another example will be using grep().

You can see both example with output so, you can understand, how it works.

Example 1:

<!DOCTYPE html>

<html>

<head>

<title>How to Remove Array Element in Jquery by Value? - ItSolutionStuff.com</title>

<script src="https://code.jquery.com/jquery-1.12.4.js"></script>

</head>

<body>

<script type="text/javascript">

var sites = [ "ItSolutionStuff.com", "HDTuto.com", "NiceSnippets.com", "Hackthestuff.com" ];

sites.splice($.inArray('HDTuto.com', sites),1);

console.log(sites);

</script>

</body>

</html>

Output:

["ItSolutionStuff.com", "NiceSnippets.com", "Hackthestuff.com"]

Example 2:

<!DOCTYPE html>

<html>

<head>

<title>How to Remove Array Element in Jquery by Value? - ItSolutionStuff.com</title>

<script src="https://code.jquery.com/jquery-1.12.4.js"></script>

</head>

<body>

<script type="text/javascript">

var sites = [ "ItSolutionStuff.com", "HDTuto.com", "NiceSnippets.com", "Hackthestuff.com" ];

var removeItem = "HDTuto.com";

var sitesNew = $.grep(sites, function(value) {

return value != removeItem;

});

console.log(sitesNew);

</script>

</body>

</html>

Output:

["ItSolutionStuff.com", "NiceSnippets.com", "Hackthestuff.com"]

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 Moment JS Subtract Seconds to Datetime Example

Read Now →

JQuery Moment Add Days to Date Example

Read Now →

JQuery Moment Get Current Date Example

Read Now →

How to Get Unique Values from Array in JQuery?

Read Now →

How to Remove Key Value from Array using JQuery?

Read Now →

Javascript Convert Array into Comma Separated String Example

Read Now →

How to Convert Array to JSON in PHP?

Read Now →

How to Split String to Array By Comma using JQuery?

Read Now →

How to Check Array Is Empty Or Null In Javascript?

Read Now →

How to Remove Empty or Null Values from JSON using JQuery?

Read Now →

How to Remove Duplicate Value from Array in JQuery?

Read Now →

How to Add Lazy Loading Image using JQuery?

Read Now →

How to Get Last Element of Array in Javascript?

Read Now →

How to Remove Specific Value from Array in JQuery?

Read Now →