32 lines
457 B
Markdown
32 lines
457 B
Markdown
# .cadoles-slide-title[Objets (2/2)]
|
|
|
|
**Itération sur les propriétés**
|
|
```js
|
|
|
|
var obj = {
|
|
pro1: 1,
|
|
prop2: 'test',
|
|
prop3: {}
|
|
};
|
|
|
|
// Boucle for..in
|
|
|
|
var value;
|
|
for(var key in obj) {
|
|
if( obj.hasOwnProperty(key) ) {
|
|
value = obj[key];
|
|
console.log('Key: ', key, 'Value:', value);
|
|
}
|
|
}
|
|
|
|
// Méthode Object.keys()
|
|
|
|
Object.keys(obj)
|
|
.forEach(function(key) {
|
|
var value = obj[key];
|
|
console.log('Key: ', key, 'Value:', value);
|
|
})
|
|
;
|
|
|
|
```
|