Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When to use an object or an array in javascript? [duplicate]

I just found out that Arrays inherit directly from Object in javascript. I'm finding the difference between an array and an object is fairly minuscule.

How do i know when to use one over the other?

like image 377
Derek Adair Avatar asked Dec 14 '10 15:12

Derek Adair


1 Answers

When you need to depend on the order of the elements in the collection, use Arrays, when order is not important, use objects. Order is not guaranteed in objects, but they provide for fast key-value pair lookups.

like image 113
Alex Avatar answered Oct 06 '22 01:10

Alex