Skip to content

Commit

Permalink
Improve answer for enumerating through JS object properties (yangshun#91
Browse files Browse the repository at this point in the history
)

I think it is necessary to mention the way to iterating over all non-enumerable properties
  • Loading branch information
nicholaslee119 authored and yangshun committed Nov 24, 2017
1 parent 9d74d2b commit 7247dbc
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions front-end/interview-questions.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down

0 comments on commit 7247dbc

Please sign in to comment.