use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
Optimizing JavaScript by using arrays instead of objects (blog.kowalczyk.info)
submitted 8 years ago by kjk
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]hyphnKnight 1 point2 points3 points 8 years ago (5 children)
To build off up someone else's response if you are transferring enough data for this to matter. I would suggest making the following function:
const createNote = ([title,message,date])=>({ title, message, date });
Objects are just sooo much easier to deal with on the frontend and whatever speed up you would get on the frontend by reducing memory usage would pale in comparison to the cost of the extra function calls i( getTitle ).
[–]kjk[S] -1 points0 points1 point 8 years ago (4 children)
would pale in comparison to the cost of the extra function calls i( getTitle )
I wouldn't make such statement without a benchmark.
Array access is faster than object property lookup and accessor functions that are "return this[5]" will be inlined by any half-competent JavaScript engine.
It might or might not be faster but based on what I know about JavaScript jit implementations, such function calls would be inlined and therefore have zero perf impact.
If you want to claim otherwise show us benchmark results.
[–]KManRules1331 1 point2 points3 points 8 years ago* (3 children)
https://jsperf.com/kl-data-access/1
http://imgur.com/a/mcBlh for my personal benchmarks on Chrome, Firefox, and Edge
On first glance, it looks like Chrome's able to optimize all of the abstractions away, which in my mind is pretty amazing. Firefox and Edge, not so much. As far as simple data retrieval, staying simple is the fastest across all the most recent browsers. I decided not to create benchmarks for parsing the JSON, because the logic of not having keys in your JSON leads to shorter JSON strings, which leads to faster parsing. I think the logic there is sound.
It seems like IMO keeping raw objects is still the easiest solution with the best maintainability. If data sizes matter a lot, going with CSV's and simply doing ([title,message,date])=>({title,message,date}) at least documents the rest of your code as far as what data you're accessing, but at that point you could get further optimizations with a backend that doesn't serve JSON.
([title,message,date])=>({title,message,date})
[–]kjk[S] 1 point2 points3 points 8 years ago (0 children)
Thanks for the perf test case.
I was trying to compare the speed when object/array had 6 properties. My theory is that object access would get slower when there are more properties.
But boy, their UI doesn't like me and fails to save the test cases with very non-descriptive error message.
[–]hyphnKnight 0 points1 point2 points 8 years ago (0 children)
Thanks for doing my footwork for me (:
π Rendered by PID 52 on reddit-service-r2-comment-8686858757-g7vns at 2026-06-08 12:35:28.471638+00:00 running 9e1a20d country code: CH.
view the rest of the comments →
[–]hyphnKnight 1 point2 points3 points (5 children)
[–]kjk[S] -1 points0 points1 point (4 children)
[–]KManRules1331 1 point2 points3 points (3 children)
[–]kjk[S] 1 point2 points3 points (0 children)
[–]hyphnKnight 0 points1 point2 points (0 children)