How to remove Objects from Associative Array in JavaScript ?
Create an associative array containing key-value pair and the task is to remove the objects from an associative array using JavaScript. We can remove objects from JavaScript associative array using delete keyword.
Approach: Declare an associative array containing key-value pair objects. Then use delete keyword to delete the array objects from an associative array.
Example 1: This example uses delete keyword to remove the objects from associative array.
<!DOCTYPE html><html> <head> <title> How to remove Objects from Associative Array in JavaScript ? </title></head> <body style="text-align:center;"> <h1 style="color:green;"> GeeksforGeeks </h1> <h3> How to remove Objects from Associative Array in JavaScript ? </h3> <script> // JavaScript code to remove // objects from associative array function deleteObjects(){ // Declaring an associative // array of objects var arr = new Object(); // Adding objects in array arr['key'] = 'Value'; arr['geeks'] = 'GeeksforGeeks'; arr['name'] = 'Rajnish'; // Checking object exist or not document.write(arr['name'] + '</br>'); // Removing object from // associative array delete arr['name']; // It gives result as undefined // as object is deleted document.write(arr['name'] + '</br>'); } // Calling function deleteObjects(); </script></body> </html> |
Output:
Example 2: This example uses delete keyword to remove the objects from associative array.
<!DOCTYPE html><html> <head> <title> How to remove Objects from Associative Array in JavaScript ? </title></head> <body style="text-align:center;"> <h1 style="color:green;"> GeeksforGeeks </h1> <h3> How to remove Objects from Associative Array in JavaScript ? </h3> <script> // JavaScript code to remove // objects from associative array function deleteObjects(){ // Declaring an associative // array of objects var arr = new Object(); // Adding objects in array arr['key'] = 'Value'; arr['geeks'] = 'GeeksforGeeks'; arr['name'] = 'Rajnish'; // Checking object exist or not document.write(arr['geeks'] + '</br>'); // Removing object from // associative array delete arr.geeks; // It gives result as undefined // as object is deleted document.write(arr['geeks'] + '</br>'); } // Calling function deleteObjects(); </script></body> </html> |
Output:
Hey geek! The constant emerging technologies in the world of web development always keeps the excitement for this subject through the roof. But before you tackle the big projects, we suggest you start by learning the basics. Kickstart your web development journey by learning JS concepts with our JavaScript Course. Now at it's lowest price ever!

