Difference between array and object in JS?

Hi there. I was wondering about the difference between array and object in JavaScript. :smile:

Please answer as fast as possible. :smile:

P :slightly_smiling_face:

You might get a better response from someone more experienced. But here’s how I understand it.

An array is simply a list: var groceryList = ["bread", "milk", "butter", "cheese", "apples"]
you can access the different items in the list with its index.

An object has properties and values. The values can be arrays: var foods = {"vegetables": ["carrots", "corn"], "fruit": ["apples", "bananas"], "meat": ["chicken", "beef"]}
You access the values of the object by accessing its property (in my example, vegetables, fruit , and meat are the properties.

2 Likes

Hello there, to add on to what has been said: it is important to distinguish between an object and an object literal.

An object literal is what has been described above, but an Array in JavaScript is an object. So is a string.

Hope this helps

1 Like