Sunday, May 12, 2024
 Popular · Latest · Hot · Upcoming
42
rated 0 times [  49] [ 7]  / answers: 1 / hits: 16815  / 12 Years ago, wed, december 5, 2012, 12:00:00

I've been trying to debug some js in Internet Explorer, and I can't figure this one out. Here's the line that is causing the error:



var numberOfColumns = Object.keys(value).length;


And the error is...



Message: Object doesn't support this property or method
Line: 640
Char: 5
Code: 0
URI: xxx


At first I thought it had something to do with the Object.keys(value).length; property, but strangely (for me anyways), the error is at char 5, which is the beginning of the variable name.



Anyways, I have no idea what's going on or how to fix it. Also, if I replace:



var numberOfColumns = Object.keys(value).length;


With ...



var numberOfColumns = 9; // troubleshooting


The error persists. Please help.



Update



jsFiddle added



http://jsfiddle.net/4Rab7/


More From » jquery

 Answers
37

The keys property is supported in IE >= 9. You are probably testing it in an earlier version. A simple workaround is:



var length = 0;
for(var prop in data){
if(data.hasOwnProperty(prop))
length++;
}


Here is a demonstration: http://jsfiddle.net/vKr8a/



See this compatibility table for more info:



http://kangax.github.com/es5-compat-table/


[#81606] Monday, December 3, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jaelynncherokeeg

Total Points: 697
Total Questions: 109
Total Answers: 104

Location: France
Member since Thu, Mar 18, 2021
3 Years ago
jaelynncherokeeg questions
Thu, May 27, 21, 00:00, 3 Years ago
Fri, Jan 24, 20, 00:00, 4 Years ago
Thu, Nov 14, 19, 00:00, 5 Years ago
Wed, Sep 18, 19, 00:00, 5 Years ago
;