1.

How To Add/remove Properties To Object In Run-time In Javascript?

Answer»

I am going to explain by example for add and remove properties from JavaScript OBJECTS as GIVE below.

This example for DELETE property.
//This is the JSON object.
var objectJSON = {
id: 1,
name: "Anil Singh",
dept: "IT"
};
//This is the process to delete
delete objectJSON.dept;
//Delete property by the array collection
MyArrayColection.prototype.remove = function (INDEX) {
this.splice(index, 3);
}
This example for add property
//This is used to add the property.
objectJSON.age = 30;
console.log(objectJSON.age); //The result is 30;
//This is the JSON object.
var objectJSON = {
id: 1,
name: "Anil Singh",
dept: "IT",
age :30
};

I am going to explain by example for add and remove properties from JavaScript objects as give below.

This example for delete property.
//This is the JSON object.
var objectJSON = {
id: 1,
name: "Anil Singh",
dept: "IT"
};
//This is the process to delete
delete objectJSON.dept;
//Delete property by the array collection
MyArrayColection.prototype.remove = function (index) {
this.splice(index, 3);
}
This example for add property
//This is used to add the property.
objectJSON.age = 30;
console.log(objectJSON.age); //The result is 30;
//This is the JSON object.
var objectJSON = {
id: 1,
name: "Anil Singh",
dept: "IT",
age :30
};



Discussion

No Comment Found