博客 / 詳情

返回

js獲取對象的屬性個數

let math = {
    subject: '數學',
    children: [
        { id: 1, title: '數一' }, 
        { id: 2, title: '數二' }, 
        { id: 3, title: '數三' }, 
        { id: 0, title: '待定' }
    ]
}
// 取對象的屬性個數
Object.getOwnPropertyNames(math).length;
Object.keys(math).length;
user avatar 1023 頭像 peter-wilson 頭像 zhangxishuo 頭像 201926 頭像 alfred_5972f8006661f 頭像 79px 頭像 qianduanlangzi_5881b7a7d77f0 頭像 huaihuaidedianti 頭像 qingji_58b3c385d0028 頭像 xiaohuoche 頭像 lawler61 頭像 xiaodaigua_ray 頭像
58 位用戶收藏了這個故事!

發佈 評論

Some HTML is okay.