Length of a JavaScript object

前端 未结 30 3168
我在风中等你
我在风中等你 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:09

    Here's how and don't forget to check that the property is not on the prototype chain:

    var element_count = 0;
    for(var e in myArray)
        if(myArray.hasOwnProperty(e))
            element_count++;
    

提交回复
热议问题