Skip to content

Commit

Permalink
Update Object.md
Browse files Browse the repository at this point in the history
  • Loading branch information
yihan12 authored Dec 14, 2023
1 parent 0b83652 commit 7ae94ce
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions javascript/Data Types/Object.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,13 @@ console.log(obj2.propfirst);
对比例1和例2不难发现,delete能删除本身的属性,但是不能删除继承的属性。删除调obj1的propfirst属性后,会影响到obj2的继承属性。

### 遍历对象

- for...in 循环 该方法依次访问一个对象及其原型链中所有可枚举的属性。
- Object.keys(o) 该方法返回对象 o 自身包含(不包括原型中)的所有可枚举属性的名称的数组。
- Object.getOwnPropertyNames(o) 该方法返回对象 o 自身包含(不包括原型中)的所有属性 (无论是否可枚举) 的名称的数组。

遍历对象的所有键:要遍历对象的所有现有可枚举键,我们可以在构造中使用for…in。值得注意的是,这允许我们只访问对象的可枚举属性(回想一下,可枚举是数据属性的四个属性之一)。例如,从Object.prototype继承的属性是不可枚举的。但是,从某处继承的可枚举属性也可以使用for… in构造来访问

```javascript
let person = {
gender : "male"
Expand Down

0 comments on commit 7ae94ce

Please sign in to comment.