問題:
I have a JavaScript object, is there a built-in or accepted best practice way to get the length of this object? 我有一個JavaScript對象,是否有內置的或公認的最佳實踐方法來獲取此對象的長度? ui
const myObject = new Object(); myObject["firstname"] = "Gareth"; myObject["lastname"] = "Simpson"; myObject["age"] = 21;
解決方案:
參考一: https://stackoom.com/question/1MF/JavaScript對象的長度參考二: https://oldbug.net/q/1MF/Length-of-a-JavaScript-object