Dave's Brain

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)); }

Add a comment

Sign in to add a comment
Copyright © 2008-2017, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.