1. Declare two syntax for objects

let obj = {'name':'jack','age':'18'}
let obj = new Object({'name':'ma'});
Copy the code

The first is usually written, and the second is the normal way

{} This is called an Object literal, and new Object() uses the constructor function

Object literals are declared more conveniently than constructor functions

So in JS, it is recommended that object literals be declared in preference

2. How do I delete object attributes

Delete obj['name']Copy the code

3. How do I view the properties of an object

View all properties of the object:

Keys (obj); View own properties + Common properties: console.dir(obj); Keys (obj), obj.__proto__ in order to print its own attributes + common attributesCopy the code

View an object property:

Let obj = {'name':'jack','age':'18'} Obj [name] = 'Lucy' obj[name] = 'Lucy' Obj [name] equivalent to obj[' Lucy ']Copy the code

4. How do I modify or add attributes of an object

Let obj = {'name':'jack','age':'18'} Let obj = {'name':'jack','age':'18'} Object. The assign (obj, {' name ':' Lucy ', 'age' : '20'}) modified method of Shared attributes: Object. Prototype ['toString'] = 'XXX' Obj.__proto__ = common or let obj = object.create (common), if you want to change it, you are recommended to use the second method. All Porto code is not recommended to change, it will cause problemsCopy the code

5.’name’ in obj and obj.hasOwnProperty(‘name’

‘name’ in obj checks whether it and its prototype have this property

Obj.hasownproperty (‘name’) checks whether it is a unique property of its own or a common property