Accessing and modifying object properties
In JavaScript programming, object data types are stored as an array of key-value pairs in an ordered manner, where the object data type format contains the keys that are used as properties of the object, it is in a string format, and the object data type value can be any type of data type. Popular data types include string data type, numeric, float, function, array, or any other data type in the object format. Where JavaScript programmers can access and modify data object properties in multiple orders.

Accessing array object properties.
There are two methods to access and control the properties of an object in a JavaScript program.
- Dot notation method.
- Bracket notation method.
Dot notation object method.
The basic and simple method to access the properties of an object created in a JavaScript program is the dot notation process.
Syntax of Dot notation object method.
object.propertyName
Example of a dot notation object.
let company = {
compname: “Vcanhelpsu”,
compcont: 91
};
console.log(company.compname); // Result – Vcanhelpsu
console.log(company.compcont); // Result – 91
Explanation of dot notation object.
Here in this program using dot notation method, we can access compname and compcont object properties of company object directly.
Limitations of dot notation in JavaScript.
Where the object property name must be a valid identifier (e.g., it must not contain empty spaces, the object identifier must not start with a numeric character, or the identifier must not use any special symbols such as @ or !, $, #).
JavaScript Bracket Notation Method.
Bracket notation is a flexible feature of object property access in JavaScript programs, it allows JavaScript programmers to access object property names that are not valid JavaScript program data type identifiers in the current program, such as object property names with empty spaces or special character symbols, or if the programmer needs to access the object property in a dynamic order, such as using a variable to indicate the name of an object property.
Syntax of JavaScript bracket notation.
object[“propertyName”]
Example of JavaScript bracket notation.
let company = {
“compname”: “Vcanhelpsu”,
“compcont”: 91
};
console.log(company[“compname”]); // Result – Vcanhelpsu
console.log(company[“compcont”]); // Result – 91
Explanation of JavaScript bracket notation.
In the above program, bracket notation allows programmers to access the first name property element, which is invalid for dot notation object properties because it contains an empty space.
Dynamic property access in JavaScript.
In JavaScript programs, bracket notation features can be used to dynamically access an object variable’s identifier property. Bracket notation features are especially useful when programmers do not know the name of a declared object property in advance.
Example of dynamic property access in JavaScript.
let company = {
compname: “Vcanhelpsu”,
compcont: 91
};
let comp=”compname”;
console.log(company[comp]); // Result – Vcanhelpsu
JavaScript Explanation of dynamic property access.
In this program example, comp is the name of the “compname” object property in the user-declared program variable, and we use the bracket notation method to access compname[comp].
Modifying Object Property in JavaScript.
JavaScript programmers can modify the property of the declared object in two orders.
Using dot notation features.
Using bracket notation features.
While modifying the object property in JavaScript programs, both the methods work in equal order.
Modifying object with dot notation in JavaScript programs.
Syntax of dot notation.
object.propertyName = newValue;
Example of syntax of dot notation.
let company = {
compname: “Vcanhelpsu”,
compcont: 01
};
company.compname = “Vcandevelop”; // here it Modifying the ‘compname’ property
company.compcont = 02; // here it Modifying the ‘compcont’ property
console.log(company.compname); // Result – Vcandevelop
console.log(company.compcont); // Result – 02
Explanation of dot notation modification.
Here in this program we use dot notation method to modify compame and compcont object properties of company object.
Making modification with bracket notation in JavaScript.
Syntax of bracket notation.
object[“propertyName”] = newValue;
Example of bracket notation.
let company = {
compname: “Vcanhelpsu”,
compcont: 01,
company[“compname”] = “Vcandevelop”; //here it Modifying the ‘compname’ property
company[“compcont”] = 04; //here it Modifying the ‘compcont’ property
console.log(company.compname); // Result – Vcandevelop
console.log(company.compcont); // Result – 04
Modification with bracket notation explained.
In this program bracket notation works just like dot notation, but it allows programmers to use dynamic property names or access special character symbol properties.
Adding New Properties with Dot Notation or Bracket Notation.
Javascript programmers can add new properties to a program object at any time by applying the dot notation or bracket notation methods.
Adding New Object with Dot Notation.
let company = {
compname: “Vcanhelpsu”,
compcont: 30
};
company.course = “javascript”; // here we adding a new property ‘course’
console.log(company.course); // Result – javascript
console.log(company.compname);
New Object with Dot Notation explained.
Here we have added a new object property course with value “course” to the company object by applying dot notation method in this program.
Adding new object properties with addition using bracket notation.
let company = {
compname: “Vcanhelpsu”,
compcont: 20
};
company[“course”] = “python”; // here we Adding a new property ‘course’
console.log(company.course); // Result – python
Explanation of new object properties with addition using bracket notation.
We have added a new object property course with value “python” using bracket notation.
Deleting JavaScript object properties.
To remove a property from an object in JavaScript, JavaScript programmers can apply the delete operator.
Syntax of deleting object properties.
delete object.propertyName;
Example of deleting object properties.
let company = {
compname: “Vcanhelpsu”,
compcont: 40,
course: “javascript”
};
delete company.course; // here we Deleting the ‘course’ object property
console.log(company.course); // Result – undefined
Explanation of deleting object properties.
In this program, course object properties have been deleted from the existing company object, and as soon as someone tries to access it, the result is in the form of undefined data type.
Checking if a property exists in an existing object.
In this program, by applying in operator or hasOwnProperty() method, we can check whether any object properties are present in a declared object or not.
Using in operator to check object properties.
let company = {
compname: “Vcanhelpsu”,
compcont: 91
};
console.log(“compname” in company); // Result – true
console.log(“course” in company); // Result – false
in operator to check object properties Explanation.
Here in this program if properties are present in declared object, even if the value of that object is undefined then also in operator returns true value.
Using hasOwnProperty() method in object.
let company = {
compname: “Vcanhelpsu”,
compcont: 91
};
console.log(company.hasOwnProperty(“compname”)); // Result – true
console.log(company.hasOwnProperty(“course”)); // Result – false
Explanation of hasOwnProperty() method in object.
In this program using hasOwnProperty() method we check whether search object properties are present in object, except properties in given prototype series.
Example of combining access and modification of object properties.
Here is an example of how a JavaScript program can access object properties, modify them, and add new object properties.
let company = {
compname: “Vcanhelpsu”,
compcont: 91
};
// let Accessing the object properties
console.log(company.compname); // Result – Vcanhelpsu
// let Modifying the object properties
company.compcont = 92;
console.log(company.compcont); // Result – 92
// let Adding a new object property
company.course = “javasript”;
console.log(company.course); // Result – javascript
// let Deleting an existing object property
delete company.compcont;
console.log(company.compcont); // Result – undefined
// let Checking if a object property exists
console.log(“course” in company); // Result – true
Explanation of combining access and modification of object.
In this program example, we access and modify the properties of company object. In this program, we add a new object property (course), delete the existing compcont object properties, and check the object properties to see if the company course object property exists or not.
Explanation of object data type properties.
- Dot notation method – Basic and simple method of accessing and modifying object properties in JavaScript programs where valid object properties are limited by the requirement of names.
- Bracket notation method – Allows more flexible, dynamic access and modification of object properties, and enables property names with empty spaces or special symbol characters.
- Adding and deleting object property – JavaScript programmers can add new properties to an object at any time using the dot or bracket notation method, and existing object properties can be removed using the delete operator.
- Existence checking object – In existing programs, the in operator and hasOwnProperty() method are required to check whether an object has a particular property.