作者热门文章
- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
除了运行循环和使用计数器之外,是否有其他方法可以找到 javascript 对象中子对象的数量?如果有帮助,我可以利用 jquery。我这样做:
var childScenesObj = [];
var childScenesLen = scenes[sceneID].length; //need to find number of children of scenes[sceneID]. This obviously does not work, as it an object, not an array.
for (childIndex in scenes[sceneID].children) {
childSceneObj = new Object();
childSceneID = scenes[sceneID].children[childIndex];
childSceneNode = scenes[childSceneID];
childSceneObj.name = childSceneNode.name;
childSceneObj.id = childSceneID;
childScenesObj .push(childSceneObj);
}
最佳答案
以下在 ECMAScript5 (Javascript 1.85) 中工作
var x = {"1":1, "A":2};
Object.keys(x).length; //outputs 2
关于javascript如何在一个对象中找到 child 的数量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7081165/
我是一名优秀的程序员,十分优秀!