What's the fastest way to count the number of keys/properties of an object? 計算對象的鍵/屬性數的最快方法是什麼? It it possible to do this without iterating over the object? 是否能夠在不迭代對象的狀況下執行此操做? ie without doing 即不作 ide
var count = 0; for (k in myobj) if (myobj.hasOwnProperty(k)) count++;
(Firefox did provide a magic __count__
property, but this was removed somewhere around version 4.) (Firefox確實提供了一個神奇的__count__
屬性,但此屬性已在版本4的某個位置刪除。) this