1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
| Array.prototype.getLength = function() { return this.length; }; var arr = ['a', 'b', 'c']; arr.name = 'June'; Object.defineProperty(arr, 'age', { enumerable: true, value: 17, writable: true, configurable: true }); for(let i of arr) { console.log(i); }
var person = { name: 'June', age: 17, city: 'guangzhou' } for(var key of Object.keys(person)) { console.log(person[key]); }
Object.entries()会返回多个由对象属性Key和Value组成的数组 const arr = { name: 'mike', age: 18 }; console.log(Object.entries(arr));
var arr = ['a', 'b', 'c']; for(let [index, value] of Object.entries(arr)) { console.log(index, ':', value); } var obj = {name: 'June', age: 17, city: 'guangzhou'}; for(let [key, value] of Object.entries(obj)) { console.log(key, ':', value); }
|