To get a list of associative array keys with JavaScript, we call the Object.keys
method.
For instance, we write
const dictionary = {
cats: [1, 2, 37, 38, 40, 32, 33, 35, 39, 36],
dogs: [4, 5, 6, 3, 2],
};
const keys = Object.keys(dictionary);
console.log(keys);
to call Object.keys
with dictionary
to return a list of key strings from the dictionary
object.