Browse - Programming Tips - How might I get the keys of a javaScript associative array?

Date: 2009jul24
Language: javaScript

Q.  How might I get the keys of a javaScript associative array?

A.  This little function does the same thing as the perl keys() builtin function.

function keys(h) { var i, a = []; for (i in h) a.push(i); return a; } function exampleUse() { var months = { jan: 31, feb: 28, mar: 31, apr: 30, may: 31, jun: 30, jul: 31, aug: 31, sep: 30, oct: 31, nov: 30, dec: 31 }; dump(keys(months)); }