Objects are now being called Associative Arrays?


#1


https://www.codecademy.com/en/courses/building-an-address-book/0/1?curriculum_id=506324b3a7dffd00020bf661


Nothing is wrong with my code. But the lesson just called an Object with several properties (keys with values) an associative array. I had understood arrays were made var arrayName = [arrayValue,arrayValue2];
This is confusing and I feel like it's a bug/typo in the lesson. Maybe just a sentence saying an object with properties can also be called an associative array would help.


Replace this line with your code.


#2

It is not a bug, and neither is it an error. An associative array consists of keys and associated values or expressions, in key: value pairs.

var object = {
    key: value
}

To access values, we use array subscript notation, object['key'] => value.

Don't let the diction throw you off. In most cases you will read, object but can visualize it as an associative array. We need the syntax when using a dynamic variable to identify key names.

for (var key in object) {
    console.log(key + ": " + object[key]);
}

#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.