
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
How to modify properties of a nested object in JavaScript?
There are two methods to modify properties of nested objects. One is Dot method and the other is Bracket method. The functionality is same for both the methods, but the only difference is their notation.
lets' discuss them in detail.
Dot method
Example
In the following example initially the value of property country is England. But using Dot notation the value is changed to India.
<html> <body> <script> var person; var txt = ''; person = { "name":"Ram", "age":27, "address": { "houseno":123, "streetname":"Baker street", "country":"England" } } document.write("Before change : " + " " + person.address.country); person.address.country = "India"; document.write("</br>"); document.write("After change : " + " " + person.address.country); </script> </body> </html>
Output
Before change : England After change : India
Bracket method
Example
In the following example the value of property 'country' is changed from England to India using Bracket notation.
<html> <body> <script> var person; var txt = ''; person = { "name":"Ram", "age":27, "address": { "houseno":123, "streetname":"Baker street", "country":"England" } } document.write("Before change : " + " " + person.address["country"]); person.address.country = "India"; document.write("</br>"); document.write("After change : " + " " + person.address["country"]); </script> </body> </html>
Output
Before change : England After change : India
- Related Articles
- How to modify an array value of a JSON object in JavaScript?
- How to find and modify a value in a nested array?
- How to duplicate Javascript object properties in another object?
- How to create object properties in JavaScript?
- How to delete object properties in JavaScript?
- How to get a subset of JavaScript object's properties?
- Constructing a nested JSON object in JavaScript
- How to convert square bracket object keys into nested object in JavaScript?
- How to get a subset of a javascript object's properties?
- JavaScript Object Properties
- How to add, access, delete, JavaScript object properties?
- Can we modify built-in object prototypes in JavaScript
- Print JSON nested object in JavaScript?
- Changing value of nested object keys in JavaScript
- Test for existence of nested JavaScript object key in JavaScript

Advertisements