JavaScript | Add new attribute to JSON object Last Updated : 25 Jun, 2021 Comments Improve Suggest changes Like Article Like Report The task is to add a JSON attribute to the JSON object. To do so, Here are a few of the most used techniques discussed.Example 1: This example adds a prop_11 attribute to the myObj object via var key. html <!DOCTYPE HTML> <html> <head> <title> JavaScript | Add new attribute to JSON object. </title> </head> <body style="text-align:center;" id="body"> <h1 style="color:green;"> GeeksForGeeks </h1> <p id="GFG_UP" style="font-size: 16px; font-weight: bold;"> </p> <button onclick="gfg_Run()"> Click here </button> <p id="GFG_DOWN" style="color:green; font-size: 20px; font-weight: bold;"> </p> <script> var el_up = document.getElementById("GFG_UP"); var el_down = document.getElementById("GFG_DOWN"); var myObj = { 'prop_1': { 'prop_12': 'value_12' } }; el_up.innerHTML = JSON.stringify(myObj); function gfg_Run() { var key = "prop_11"; myObj.prop_1[key] = "value_11"; el_down.innerHTML = JSON.stringify(myObj); } </script> </body> </html> Output: Before clicking on the button: After clicking on the button: Example 2: This example adds a prop_11 attribute to the myObj with value value_11. html <!DOCTYPE HTML> <html> <head> <title> JavaScript | Add new attribute to JSON object. </title> </head> <body style="text-align:center;" id="body"> <h1 style="color:green;"> GeeksForGeeks </h1> <p id="GFG_UP" style="font-size: 16px; font-weight: bold;"> </p> <button onclick="gfg_Run()"> Click here </button> <p id="GFG_DOWN" style="color:green; font-size: 20px; font-weight: bold;"> </p> <script> var el_up = document.getElementById("GFG_UP"); var el_down = document.getElementById("GFG_DOWN"); var myObj = { 'prop_1': { 'prop_12': 'value_12' } }; el_up.innerHTML = JSON.stringify(myObj); function gfg_Run() { myObj.prop_1["prop_11"] = "value_11"; el_down.innerHTML = JSON.stringify(myObj); } </script> </body> </html> Output: Before clicking on the button: After clicking on the button: Comment More infoAdvertise with us Next Article JavaScript | Add new attribute to JSON object P PranchalKatiyar Follow Improve Article Tags : JavaScript Web Technologies JSON Similar Reads JavaScript | Remove a JSON attribute In this article, we will see how to remove a JSON attribute from the JSON object. To do this, there are few of the mostly used techniques discussed. First delete property needs to be discussed. Delete property to Remove a JSON Attribute This keyword deletes a property from an object: This keyword de 2 min read JavaScript- Add an Object to JS Array In JavaScript, arrays are used to store multiple values in a single variable, and objects are collections of properties and values. Sometimes, we may need to add an object to an array to manage data more effectively. These are the following ways to add an object to a JS array: Using JavaScript Array 4 min read How to Iterate JSON Object in JavaScript? In JavaScript, there are different ways to iterate over the properties of a JSON object. Letâs look at the most common techniques.1. Using for...in LoopThe for...in loop is a simple way to go through the properties of a JSON object. It loops over the keys of the object. Inside the loop, we can acces 4 min read JavaScript JSON Objects JSON (JavaScript Object Notation) is a handy way to share data. It's easy for both people and computers to understand. In JavaScript, JSON helps organize data into simple objects. Let's explore how JSON works and why it's so useful for exchanging information.const jsonData = { "key1" : "value1", ... 3 min read Converting JSON text to JavaScript Object Pre-requisite: JavaScript JSON JSON (JavaScript Object Notation) is a lightweight data-interchange format. As its name suggests, JSON is derived from the JavaScript programming language, but itâs available for use by many languages including Python, Ruby, PHP, and Java and hence, it can be said as l 3 min read Like