Object traversal and storage

1. traverse the object properties and methods:
The first :
for in
navigating the object of all the "enumerable" properties, including its own property and inheritance of property

  var obj={
       name:"qianjiaji",
       age:18,
       height:180,
       weight:120
  }
  for(var i in obj){
      console.log(i)
      console.log(obj[i])
  }

The second :
Object.keys (obj)
Parameters: enumeration to return to their own object properties
Return Value: a string array given object attributes represent all enumerable

 var obj={
       name:"qianjiaji",
       age:18,
       height:180,
       weight:120
  }
 console.log(Object.keys(obj))  

Third :
Object.getOwnPropertyNames (obj)
Object.getOwnPropertyNames returns an array containing all the object's own properties (excluding Symbol properties, including but not enumerated attribute) key name.

 var obj={
       name:"qianjiaji",
       age:18,
       height:180,
       weight:120
  }
 console.log(Object.getOwnPropertyNames(obj))  

The fourth
Object.getOwnPropertySymbols (obj)
Object.getOwnPropertySymbols returns an array containing the names of all the key attributes of the object itself Symbol.

 var obj={
       name:"qianjiaji",
       age:18,
       height:180,
       weight:120
  }
 console.log(Object.getOwnPropertySymbols(obj))  

The fifth
Reflect.ownKeys (obj)
Reflect.ownKeys returns an array containing the object itself of all the key names, regardless of the key name is Symbol or string, whether or not enumerable.

 var obj={
       name:"qianjiaji",
       age:18,
       height:180,
       weight:120
  }![在这里插入图片描述](https://img-blog.csdnimg.cn/20200303205902887.jpg?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0phbWVzSEtL,size_16,color_FFFFFF,t_70)
 console.log(Reflect.ownKeys(obj))  

2. The object storage
memory: consists of four parts, stack memory heap memory segment code segment data
objects are a reference, which is stored in a stack memory address that points to the memory heap, the heap memory and holds the attributes of the object method, the method is directed code segment
is between two objects independent
structure as shown below:
Here Insert Picture Description

Published 25 original articles · won praise 0 · Views 637

Guess you like

Origin blog.csdn.net/JamesHKK/article/details/104632900