Is that an Array ? 14. Building an Adress book JS


#1

Just a simple question : is that code an array ? I thought it was an object ?

var bob = {
firstName: “Bob”,
lastName: “Jones”,
phoneNumber: “(650) 777-777”,
email: "bob.jones@example.com"
};
You have an array when you have brackets [ ] , haven’t you ? Am I wrong ?
thanks for a answer .
Here is the link
https://www.codecademy.com/courses/building-an-address-book/0/1?curriculum_id=506324b3a7dffd00020bf661#


#2

this one of the confusing things of javascript:

objects == associative array

they are the same, which is why we are allowed to both:

// object notation
bob.firstName

and:

// associative array notation
bob["firstName"]

#3

Extending what @stetim94 explained to you, languages have different data types. Some combine things together such as number in JavaScript, where other languages would break it out into separate data types such as int, float, double, etc.

Arrays are object data types in JavaScript. Want to see that for yourself? Put this into your code and it’ll display the data type for you.

console.log(typeof bob); //-> object

Technically then bob is an “object” data type. Right? We can also express it as an associative array, meaning that we have a key/value pair relationship.

As @stetim94 said, it is confusing. Absolutely. When we wrap up other representations into one data type, it can be confusing when we know about arrays as defined in computer science.

But you can think of an object in JavaScript as a collection. Therefore, it can be an array or an object with properties and functionality.

You can learn more here on MDN:


#4

Thanks a lot for your explanation Stetim !


#5

Great Tonya ! typeof to check what is the code’s nature , that’s great ! thanks


#6

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