JSON Delete a Key from an object

JSON Deleting Keys from the object

In the following example, we will delete keys (married and partner) from the first object in an array (data) by using JSON's dot notation and bracket notation.


HTML Editor
<!DOCTYPE html> <html lang="en-US"> <body> <h1>JSON Deleting a Key from the object</h1> <button onclick="myFunction()">Click Me</button> <script> var data = [ { "name": "Mike", "age": 36, "married": true, "partner": "Jade" } ] function myFunction(){ // Deleting a key (married) from the first object by using dot notation delete data[0].married; // Deleting a key (partner) from the first object by using bracket notation delete data[0]["partner"]; console.log(data); } </script> </body> </html>


delete obj.key; //or delete obj["key"];

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author