我有以下 Json 结果:
(取自控制台)
data
Object {0: Object, 1: Object, 2: Object, 3: Object, 4: Object, 5: Object, 7: Object}
如果我在控制台中执行data[0]
,我会得到以下结果:
Object {id: 125, Module_id: 2, academy_id: 7, Team_id: 5, end: "2014-08-12 00:00:00"…}
但是,当我执行data.length
时,该值是未定义
,任何人都可以告诉我发生了什么事吗?
最佳答案
Object.keys(data).length;
DEMO
The Object.keys() method returns an array of a given object's own enumerable properties, in the same order as that provided by a for...in loop (the difference being that a for-in loop enumerates properties in the prototype chain as well).
关于JavaScript Ajax 数据是数组,但长度未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25308131/