方法:1、用「Object.keys(obj)」遍歷對象,傳回一個包含物件本身所有可枚舉屬性的鍵名數組;2、用「Reflect.ownKeys(obj)」遍歷對象,傳回一個包含物件本身的所有鍵名的陣列;3、用「for in」迴圈遍歷物件等。
本教學操作環境:windows10系統、ECMAScript 6.0版、Dell G3電腦。
es6遍歷物件的方法是什麼
1. for…in
#for…in迴圈遍歷物件本身的和繼承的可枚舉屬性(不含Symbol 屬性)。
2. Object.keys(obj)
Object.keys傳回一個數組,包括物件本身的(不含繼承的)所有可枚舉屬性(不含Symbol 屬性)的鍵名。
3. Object.getOwnPropertyNames(obj)
Object.getOwnPropertyNames傳回一個陣列,包含物件本身的所有屬性(不含Symbol 屬性,但包含不可枚舉屬性)的鍵名。
4. Object.getOwnPropertySymbols(obj)
#Object.getOwnPropertySymbols傳回數組,包含物件本身的所有 Symbol 屬性的鍵名。
5. Reflect.ownKeys(obj)
Reflect.ownKeys傳回一個數組,包含物件本身的所有鍵名,不管鍵名是Symbol 或字串,也不管是否可枚舉。
以上的 5 種方法遍歷物件的鍵名,都遵守同樣的屬性遍歷的次序規則。
首先遍歷所有數值鍵,依照數值升序排列。
其次遍歷所有字串鍵,依照加入時間升序排列。
最後遍歷所有 Symbol 鍵,依照加入時間升序排列。
Reflect.ownKeys({ [Symbol()]:0, b:0, 10:0, 2:0, a:0 }) // [‘2′, ’10’, ‘b’, ‘a’, Symbol()]
【相關推薦:javascript影片教學、web前端】
以上是es6遍歷物件的方法是什麼的詳細內容。更多資訊請關注PHP中文網其他相關文章!

No,youshouldn'tusemultipleIDsinthesameDOM.1)IDsmustbeuniqueperHTMLspecification,andusingduplicatescancauseinconsistentbrowserbehavior.2)Useclassesforstylingmultipleelements,attributeselectorsfortargetingbyattributes,anddescendantselectorsforstructure

html5aimstoenhancewebcapabilities,Makeitmoredynamic,互動,可及可訪問。 1)ITSupportsMultimediaElementsLikeAnd,消除innewingtheneedtheneedtheneedforplugins.2)SemanticeLelelemeneLementelementsimproveaCceccessibility inmproveAccessibility andcoderabilitile andcoderability.3)emply.3)lighteppoperable popperappoperable -poseive weepivewebappll

html5aimstoenhancewebdevelopmentanduserexperiencethroughsemantstructure,多媒體綜合和performanceimprovements.1)SemanticeLementLike like,和ImproVereAdiability and ImproVereAdabilityActibility.2)and tagsallowsemlessallowseamelesseamlessallowseamelesseamlesseamelesseamemelessmultimedimeDiaiaembediiaembedplugins.3)。 3)3)

html5isnotinerysecure,butitsfeaturescanleadtosecurityrisksifmissusedorimproperlyimplempled.1)usethesand andboxattributeIniframestoconoconoconoContoContoContoContoContoconToconToconToconToconToconTedContDedContentContentPrenerabilnerabilityLikeClickLickLickLickjAckJackJacking.2)

HTML5aimedtoenhancewebdevelopmentbyintroducingsemanticelements,nativemultimediasupport,improvedformelements,andofflinecapabilities,contrastingwiththelimitationsofHTML4andXHTML.1)Itintroducedsemantictagslike,,,improvingstructureandSEO.2)Nativeaudioand

使用ID選擇器在CSS中並非固有地不好,但應謹慎使用。 1)ID選擇器適用於唯一元素或JavaScript鉤子。 2)對於一般樣式,應使用類選擇器,因為它們更靈活和可維護。通過平衡ID和類的使用,可以實現更robust和efficient的CSS架構。

html5'sgoalsin2024focusonrefinement和optimization,notNewFeatures.1)增強performanceandeffipedroptimizedRendering.2)inviveAccessibilitywithRefinedwithRefinedTributesAndEllements.3)explityconcerns,尤其是withercercern.4.4)

html5aimedtotoimprovewebdevelopmentInfourKeyAreas:1)多中心供應,2)語義結構,3)formcapabilities.1)offlineandstorageoptions.1)html5intoryements html5introctosements introdements and toctosements and toctosements,簡化了inifyingmediaembedingmediabbeddingingandenhangingusexperience.2)newsements.2)


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

SublimeText3 英文版
推薦:為Win版本,支援程式碼提示!

PhpStorm Mac 版本
最新(2018.2.1 )專業的PHP整合開發工具

SAP NetWeaver Server Adapter for Eclipse
將Eclipse與SAP NetWeaver應用伺服器整合。

Safe Exam Browser
Safe Exam Browser是一個安全的瀏覽器環境,安全地進行線上考試。該軟體將任何電腦變成一個安全的工作站。它控制對任何實用工具的訪問,並防止學生使用未經授權的資源。

WebStorm Mac版
好用的JavaScript開發工具