mirror of
https://github.com/yangshun/tech-interview-handbook.git
synced 2026-02-03 10:34:43 +08:00
Improve answer for enumerating through JS object properties (#91)
I think it is necessary to mention the way to iterating over all non-enumerable properties
This commit is contained in:
committed by
Yangshun Tay
parent
9d74d2b836
commit
7247dbcaf7
@@ -1240,6 +1240,7 @@ For objects:
|
||||
|
||||
- `for` loops - `for (var property in obj) { console.log(property); }`. However, this will also iterate through its inherited properties, and you will add an `obj.hasOwnProperty(property)` check before using it.
|
||||
- `Object.keys()` - `Object.keys(obj).forEach(function (property) { ... })`. `Object.keys()` is a static method that will lists all enumerable properties of the object that you pass it.
|
||||
- `Object.getOwnPropertyNames()` - `Object.getOwnPropertyNames(obj).forEach(function (property) { ... })`. `Object.getOwnPropertyNames()` is a static method that will lists all enumerable and non-enumerable properties of the object that you pass it.
|
||||
|
||||
For arrays:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user