File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -54,16 +54,29 @@ Object.entries(anObject).forEach(function ([key, value]) {
5454// iterate over the object and its full prototype chain
5555let key ;
5656for ( key in anObject ) {
57- anObject [ key ] ; // value
57+ const value = anObject [ key ] ;
5858}
5959
60+ // iterate over all own Properties including Symbols and non-enumerables (anti-pattern)
61+ Reflect . ownKeys ( anObject ) . forEach ( function ( key ) {
62+ const value = anObject [ key ] ;
63+ } ) ;
64+
65+ // iterate over own Properties including non-enumerables (anti-pattern)
66+ Object . getOwnPropertyNames ( anObject ) . forEach ( function ( key ) {
67+ const value = anObject [ key ] ;
68+ } ) ;
69+
6070// has a key
6171anObject . hasOwnProperty ( "key" ) ;
6272
6373// has safe, works even when anObject has a key "hasOwnProperty"
6474// also works for Objects without prototype
6575Object . prototype . hasOwnProperty . call ( anObject , "key" ) ;
66- Reflect . has ( anObject , "key" )
76+
77+ // has a key, or it can be found in the prototype chain
78+ "key" in anObject ;
79+ Reflect . has ( anObject , "key" ) ;
6780
6881// remove a value
6982anObject [ "key" ] = undefined ;
You can’t perform that action at this time.
0 commit comments