How to remove key from array in jquery ?

Share Me
  •  
  •  
  •  
  • 1
  •  
  •  
  •  
  •  
  •  
  •  
  •  
    1
    Share
How to remove key from array in jquery

Hello Dev’s Today now in this article, I will give you a simple example of how to remove key from array by using jquery. So now we can easily know about how to delete any key value pair from jquery array. From here you can know how to remove key from array in jquery.

Now you can use any one from here as you need. So we can easily delete any key value from any array by using splice function of js array. Or also we have a jquery array key and we need to remove it then we can also remove it by using “delete”.

Example 1:

Our first Example by Using jquery array key remove from “delete”.

<!DOCTYPE html>
<html>
<head>
	<title> Array To Remove Key </title>
</head>
<body>

<script type="text/javascript">
	var myArray = new Array();
		myArray['key1'] = 'PHP';
		myArray['key2'] = 'Laravel';
		myArray['key3'] = 'JAVA';
	delete myArray['key1'];

	console.log(myArray);
</script>
</body>
</html>

Output:

Array(2)
key2: "Laravel"
key3: "JAVA

Example 2:

Our second Example by Using jquery array key remove from splice function.

<!DOCTYPE html>
<html>
<head>
	<title> Array To Remove Key </title>
</head>
<body>

<script type="text/javascript">
var myArray = ['PHP', 'Laravel', 'JAVA'];

myArray.splice(2,2);

console.log(myArray);

</script>
</body>
</html>

OutPut

Array(2)
0: "PHP"
1: "Laravel"

Read Also : Laravel 8 Custom Middleware Tutorial Example

Thanks for read. I hope it help you. For more you can follow us on facebook

About Shahriar Sagor

My name is Shahriar sagor. I'm a developer. I live in Bangladesh and I love to write tutorials and tips that will help to other Developer's. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.

View all posts by Shahriar Sagor →