How to remove key from array in jquery ?

13-Nov-2019

.

Admin

How to remove key from array in jquery ?

Hii guys,

In this article,I will give simple example of remove key from array jquery. we can easily delete key value pair from jquery array..

You can use any one as you need. we can easily delete key value from array using splice function of js array. Or you have jquery array key and you need to remove it then you can remove it using "delete".

Example 1:


First Example 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:

Second Example 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"

It will help you...

#Jquery