I have an associative array in JavaScript:

var dictionary = {
    "cats": [1,2,3,4,5],
    "dogs": [6,7,8,9,10]
};

How do I get this dictionary’s keys? I.e., I want

var keys = ["cats", "dogs"];

Just to get the terminology correct – there is no such thing as an ‘associative array’ in JavaScript – this is technically just an object and it is the object keys we want.

6 Answers
6

Leave a Reply

Your email address will not be published. Required fields are marked *