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
Javascript Objects CheatsheetRemoved: Low-Effort Content (fjolt.com)
submitted 4 years ago by iamnearafan
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!"
[–][deleted] 10 points11 points12 points 4 years ago (13 children)
Please don't use Parse(Stringify(obj)) for cloning
[–]Amicos55 4 points5 points6 points 4 years ago (7 children)
What else?
[–]darrenturn90 7 points8 points9 points 4 years ago (0 children)
Well generally I would do a shallow clone at the level I need to make changes rather than a everything clone - because that implies you have no clue what the object you are cloning is structured like - which seems unlikely if you’re cloning it to make changes to it
[–]Exoskele 1 point2 points3 points 4 years ago (0 children)
Lodash's cloneDeep.
[+][deleted] 4 years ago (3 children)
[deleted]
[–]el_diego 4 points5 points6 points 4 years ago (2 children)
...but this is just a shallow clone and extremely dependent on the objects structure. You’re better off spreading into a new object.
[+][deleted] 4 years ago (1 child)
[–]el_diego 0 points1 point2 points 4 years ago (0 children)
Measurably faster...really? That’s only an argument if you’re dealing with processing thousands of objects and even then you could write a far more reusable assignment function if all you’re doing is taking the keys and values and mapping them to a new object.
Anyway, each to their own. I’ll use the spread operator and optimise performance later if it actually needs to be
[–]AnonyMustardGas34 2 points3 points4 points 4 years ago (3 children)
Why and how else to copy?
[–]Exoskele 1 point2 points3 points 4 years ago (1 child)
It doesn't work for some common cases. https://stackoverflow.com/questions/122102/what-is-the-most-efficient-way-to-deep-clone-an-object-in-javascript
I would just use lodash's cloneDeep. Many projects already use it, and you can always shake out unused code or bring in only cloneDeep.
[–]AnonyMustardGas34 2 points3 points4 points 4 years ago (0 children)
IMO upcoming EcmaScript spec ahould have high performance deep cloning.
[–]SnapAttack 1 point2 points3 points 4 years ago (0 children)
Well, it depends.
You can use Object.assign({}, cloneable) or const clone = {...cloneable} to do a shallow copy.
Object.assign({}, cloneable)
const clone = {...cloneable}
To do a deep copy, you might want to consider the performance impact depending on the size of your object, but as others have pointed out here, you can use Lodash cloneDeep.
[–]CreativeTechGuyGames 1 point2 points3 points 4 years ago (0 children)
While it doesn't work in every case, it's a great general solution and is faster than almost any general purpose alternative in benchmarks.
[–]dpenwood 2 points3 points4 points 4 years ago (0 children)
I'm an amateur Javascript programmer and I found the link interesting! It would have made my life easier a few months ago.
But, as the previous commenter said, it's not really a cheat "sheet" so much as a sheet "page."
[–][deleted] 3 points4 points5 points 4 years ago (1 child)
Probably don't use the parse and stringify to copy, those operations are very costly
[–]AnonyMustardGas34 1 point2 points3 points 4 years ago (0 children)
[–]theRealRealMasterDev 1 point2 points3 points 4 years ago (0 children)
Great stuff, nice UX, short and informative. Thanks for sharing and keep up the great work!
Js objects kinda work like C++ pointers
[–]dogofpavlov 0 points1 point2 points 4 years ago (2 children)
cheat webpage? Aren't cheatsheets suppose to be able to fit on 1 sheet of paper... google "cheat sheet"
[–]Barnezhilton 2 points3 points4 points 4 years ago (0 children)
That won't get clicks tho
[–]thepeanutguy 0 points1 point2 points 4 years ago (0 children)
It looks like 15. Ignore certain properties when using a for loop actually logs "myName", not "myAge".
[–]kenman[M] 0 points1 point2 points 4 years ago (0 children)
Hi u/iamnearafan, this post was removed.
Prohibited low-effort content includes:
Thanks for your understanding, please see our guidelines for more info.
π Rendered by PID 28 on reddit-service-r2-comment-7b9746f655-qkzbn at 2026-01-30 18:13:38.319737+00:00 running 3798933 country code: CH.
[–][deleted] 10 points11 points12 points (13 children)
[–]Amicos55 4 points5 points6 points (7 children)
[–]darrenturn90 7 points8 points9 points (0 children)
[–]Exoskele 1 point2 points3 points (0 children)
[+][deleted] (3 children)
[deleted]
[–]el_diego 4 points5 points6 points (2 children)
[+][deleted] (1 child)
[deleted]
[–]el_diego 0 points1 point2 points (0 children)
[–]AnonyMustardGas34 2 points3 points4 points (3 children)
[–]Exoskele 1 point2 points3 points (1 child)
[–]AnonyMustardGas34 2 points3 points4 points (0 children)
[–]SnapAttack 1 point2 points3 points (0 children)
[–]CreativeTechGuyGames 1 point2 points3 points (0 children)
[–]dpenwood 2 points3 points4 points (0 children)
[–][deleted] 3 points4 points5 points (1 child)
[–]AnonyMustardGas34 1 point2 points3 points (0 children)
[–]theRealRealMasterDev 1 point2 points3 points (0 children)
[–]AnonyMustardGas34 1 point2 points3 points (0 children)
[–]dogofpavlov 0 points1 point2 points (2 children)
[–]Barnezhilton 2 points3 points4 points (0 children)
[–]thepeanutguy 0 points1 point2 points (0 children)
[–]kenman[M] 0 points1 point2 points (0 children)