Get to know MDN better
此頁面由社群從英文翻譯而來。了解更多並加入 MDN Web Docs 社群。
This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2017年3月.
Object.entries() 靜態方法回傳給定之物件自己的可枚舉字串以字串為鍵的屬性之鍵值對陣列。
一個物件。
給定之物件自己的可枚舉字串以字串為鍵的屬性之鍵值對陣列。每個鍵值對都是一個包含兩個元素的陣列:第一個元素是屬性鍵(總是字串),第二個元素是屬性值。
Object.entries() 傳回一個陣列,其元素是與直接在 object 上找到的可枚舉字串以字串為鍵的屬性之鍵值對相對應的陣列。這與使用 for...in 迴圈進行迭代相同,只不過 for...in 迴圈也會列舉原型鏈中的屬性。Object.entries() 傳回的陣列的順序與 for...in 迴圈給的順序相同。
如果你只需要屬性鍵,可改用 Object.keys()。如果你只需要屬性值,可改用 Object.values()。
非物件參數會被強制轉換為物件,而 undefined 和 null 不能被強制轉換為物件,且會先拋出 TypeError。僅字串可擁有自己的可枚舉屬性,其它所有的原始值 都會變成空陣列。
Map() 建構子接受可迭代的 entries。你可以藉由 Object.entries 輕鬆地將 Object 轉換為 Map:
你可以使用陣列解構輕鬆地迭代物件。
| ECMAScript® 2027 Language Specification # sec-object.entries |
Enable JavaScript to view this browser compatibility table.
This page was last modified on 2025年7月14日 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.