Open In App

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
 

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
 

Output: 
 


  • Before clicking on the button: 
     

  •  

  • After clicking on the button: 
     

  •  


 


Similar Reads