1for (var name in object) {
2 if (object.hasOwnProperty(name)) {
3 // do something with name
4 }
5}
6
7// OR
8
9const hero = {
10 name: 'Batman'
11};
12
13hero.hasOwnProperty('name'); // => true
14hero.hasOwnProperty('realName'); // => false
1const hero = {
2 name: 'Batman'
3};
4
5hero.hasOwnProperty('name'); // => true
6hero.hasOwnProperty('realName'); // => false