Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

firefox: keys is not a function

I'm getting .keys is not a function on every object, using firefox 32beta but also with earlier firefox versions. Unsure what's is the cause?

var controls={'txt':{},'btn':{}}; alert(controls.keys()); 
like image 236
aelgoa Avatar asked Sep 24 '14 19:09

aelgoa


People also ask

How do you solve the is not a function error in JavaScript?

The TypeError: "x" is not a function can be fixed using the following suggestions: Paying attention to detail in code and minimizing typos. Importing the correct and relevant script libraries used in code. Making sure the called property of an object is actually a function.

Does object keys preserve order?

YES (but not always insertion order). Most Browsers iterate object properties as: Integer keys in ascending order (and strings like "1" that parse as ints) String keys, in insertion order (ES2015 guarantees this and all browsers comply)

How do you find the length of an object?

Answer: Use the Object. keys() Method You can simply use the Object. keys() method along with the length property to get the length of a JavaScript object. The Object. keys() method returns an array of a given object's own enumerable property names, and the length property returns the number of elements in that array.


1 Answers

If you want Object.keys(), you should use Object.keys(controls). See the MDN link for details.

like image 132
TML Avatar answered Sep 19 '22 11:09

TML