Skip to content

Commit 7247dbc

Browse files
nicholaslee119yangshun
authored andcommitted
Improve answer for enumerating through JS object properties (yangshun#91)
I think it is necessary to mention the way to iterating over all non-enumerable properties
1 parent 9d74d2b commit 7247dbc

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

front-end/interview-questions.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1240,6 +1240,7 @@ For objects:
12401240

12411241
- `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.
12421242
- `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.
1243+
- `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.
12431244

12441245
For arrays:
12451246

0 commit comments

Comments
 (0)