1: Adding object properties dynamically
var obj = new Object ();
Console.log (Obj.username);
Obj.username = "haha";
Console.log (Obj.username);
Undefined
haha
denoted by "[]". Written obj["username"] = "haha";
var obj = new Object ();
Console.log (Obj.username);
obj["username"] = "haha";
Console.log (Obj.username);
Undefined
haha
You can also define directly
var obj = {username: "haha", Password: "123"};
Console.log (Obj.username);
Console.log (Obj.password);
haha
123
2: Delete attribute , use Delete
var obj = new Object ();
obj["username"] = "haha";
Console.log (Obj.username);
Delete Obj.username;
Console.log (Obj.username);
haha
//undefined
3: Modify original property, add new attribute
var json = {
"Age": 24,
"Name": "Haha"
};
Modify The age value in Json
Json["age"] = 30;
Console.log (Json.age);
30
increase the sex value in Json
json["sex"] = "w";
Console.log (Json.sex);
W
4:json object and Json string Transfer
Json.parse (JSONSTR); you can convert a json string into a JSON object
var jsobj = {};
Jsobj.testarray = [n/a];
Jsobj.name = ' CSS3 ';
jsobj.date = ' 2017 ';
Console.log (Jsobj)
Console.log (typeof (Jsobj));
var str = json.stringify (jsobj);
var str1 = json.parse (str);
Console.log (str)
Console.log (typeof (str));
Console.log (STR1)
Console.log (typeof (STR1));
Object {testarray:array[3], name: "CSS3", Date: "2017"}
Object
{"Testarray": [[+], "name": "CSS3", "date": "2017"}
String
Object {testarray:array[3], name: "CSS3", Date: "2017"}
Object
Json.stringify (Jsonobj); you can convert a JSON object into a json string
var jsobj = {};
Jsobj.testarray = [n/a];
Jsobj.name = ' CSS3 ';
jsobj.date = ' 2017 ';
Console.log (Jsobj)
Console.log (typeof (Jsobj));
var str = json.stringify (jsobj);
Console.log (str)
Console.log (typeof (str));
Object {testarray:array[3], name: "CSS3", Date: "2017"}
Object
{"Testarray": [[+], "name": "CSS3", "date": "2017"}
String
JavaScript Object Properties Additions, deletions, JSON objects and string conversion methods, etc.