In JavaScript,

arrays use numbered indexes.  

objects use named indexes.

The JavaScript Array class is a global object. Read more in details: JavaScript Arrays: A Separate Data Type Or Objects?

Objects can be mutable: What Is Object Mutability In JavaScript?

Arrays can be mutable too because arrays are kind of objects at the end.

When to Use Arrays

JavaScript does not support associative arrays.

You should use arrays when you want the element names to be numbers.

That means, you would want to use arrays when order is the most important factor to organize your data.

When to Use Objects

You should use objects when you want the element names to be strings (text).

Which means, when you care about the label more than indexes, use objects. Making it a nice key value pair.

0 Comments

Leave a reply

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