How can I print the length of this JSON Object?
This question already has an answer here:
Arrays have a length
property. Objects do not (by default). I think the problem is on the php end ... You should be encoding an array and sending that back instead. Arrays are zero-indexed, so that may be the problem. Perhaps json_encode(array_values($msg))
.
If your keys are correct after all, give Object.keys(msg).length
a shot.
This can be a duplicate of Length of a JavaScript object
Look at the accepted answer.
BTW, just found googling "javascript object length" ;)
EDIT:
It's true that objects don't have a length property, and you can get the length with Object.keys(foobar).length, but it won't work in IE8 (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys)
链接地址: http://www.djcxy.com/p/27272.html上一篇: 在Javascript中计算长度
下一篇: 我怎样才能打印这个JSON对象的长度?