hguser
hguser

Reputation: 36058

eval json data get different length in IE and firefox

I got json data from the server by ajax:

request.responseText=[{name:xxx},{name:xxx},{name:xx}].

Then I use the

var data=eval(request.responseText);

alert(data.length);

In IE,it is "4",while in Firefox it is "3".

Use the IE debugger I found that the element in data is like:

[Methods]
[0]
[1]
[2]

So itis length is 4.

I wonder why?

Upvotes: 0

Views: 425

Answers (2)

airportyh
airportyh

Reputation: 22668

My guess is that the server returned data with a trailing comma, for example:

[1, 2, 3, ]

In IE, this array will be interpreted as having a length 4, while in standard compliant browsers, it will have a length 3.

Upvotes: 2

SLaks
SLaks

Reputation: 887797

[Methods] is a separate node shown by the debugger to separate functions from other values.
It does not actually exist in the object.

If an array has three items named 0, 1, and 2, its length will be 3.

Upvotes: 0

Related Questions