0

我有一个包含多个数组的对象。我需要知道这个对象中的数组数量。

这是创建地图对象的代码:

function parseXML(xData, Status){
  var map = {}; //init the map
  var web = $(xData.responseXML).find("Web");
  for (var i = 0; i < web.length; i++) {
  //we create a index for our links based on the depth of them by `/`
    var m = web[i].attributes['Url'].value.substring(23, web[i].attributes['Url'].value.length).split('/').length; 

    map[m] = map[m] || []; //make sure we leave alone the old values if there is none init with new array
    map[m].push(web[i].attributes['Url'].value); //push new value to node
  }
  console.log(map);
  createNav(map);
}

我试过了:

console.log('有'+map.length+"本站有等级"); 但我得到 map.length = undefined。

4

1 回答 1

3
map.length = 0;
for (item in map) {
    if (map.hasOwnProperty(item) && map[item] instanceof Array) {
        map.length++
    }
}
于 2013-10-20T00:55:07.140 回答