Length of a JavaScript object

前端 未结 30 3839
我在风中等你
我在风中等你 2020-11-21 04:35

I have a JavaScript object. Is there a built-in or accepted best practice way to get the length of this object?

const myObject = new Object();
myObject["         


        
30条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-21 05:12

    The simplest way is like this:

    Object.keys(myobject).length
    

    Where myobject is the object of what you want the length of.

提交回复
热议问题