- United States
- Has been a member for 4-5 years
- Exclusive Author
- Author was Featured
- Sold between 50 000 and 100 000 dollars
- Item was Featured
- Contributed a Tutorial to a Tuts+ Site
- Author had a Free File of the Month
Disregard the title of that link. The test originally started as something else and then evolved.
Probably need to do more tests but from that sample it looks like Arrays are faster for instances when you need to store both a key and a value. Certainly Objects are prettier/better organized, so deciding to use the Array approach probably depends on what you’re doing.
In the Array example, an additional 10k Arrays are created for each loop compared to the Object example. So essentially, 2[] < 1{}
- United States
- Has been a member for 4-5 years
- Exclusive Author
- Author was Featured
- Sold between 50 000 and 100 000 dollars
- Item was Featured
- Contributed a Tutorial to a Tuts+ Site
- Author had a Free File of the Month
small edit to the Object loop (wasn’t actually reading the property’s value before)
Arrays are designed for enumeration; they’ll always be faster than objects when it comes to that. But you also have to factor in ease-of-use. Yes, you can use a two element array to contain a key/value pair, but that stinks for an API .
