1、object.keys
for (var key of Object.keys(someObject)) { console.log(key + ': ' + someObject[key]); }
2、使用 Generator 函式將物件重新包裝成陣列
function* entries(obj) { for (let key of Object.keys(obj)) { yield [key, obj[key]]; } } for (let [key, value] of entries(obj)) { console.log(key, '->', value); }