TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

New JavaScript Set Methods

92 pointsby soheilpro11 months ago

11 comments

esprehn11 months ago
I'm very excited this finally shipped everywhere! Prior to this Set wasn't much more than a Map<any, true> since it had no actual Set operations.
mcphage11 months ago
Oh, that's a relief. Having "set" objects in JS, without having any of the standard set operations, didn't make a lot of sense.
bsmth11 months ago
Blog post author here in case there's any feedback or questions. Thanks for sharing :)
评论 #40777735 未加载
wruza11 months ago
It was replaceAll in 2021 and now this! Who knows what we’ll get in 2030. Maybe Array.prototype.last() even.
评论 #40785229 未加载
orangepanda11 months ago
&gt; It&#x27;s also typically faster to check if an element is in a set as opposed to in an Array<p>What optimisations allow that? As sets in javascript maintain insertion order, aren’t lookups O(n) ?
评论 #40776651 未加载
评论 #40782048 未加载
评论 #40775981 未加载
philipwhiuk11 months ago
It&#x27;s a pity that you can&#x27;t implement a function in an object to consider it equal to another object with the same member values.
评论 #40783484 未加载
throw15675422811 months ago
This&#x27;ll help with AoC. Just need sensible tuples now and we&#x27;ll be golden. See you in ten years.
bavell11 months ago
Perhaps it&#x27;s asking too much but it would be great to see performance comparisons of these new set methods versus naive JS.<p>Not sure when I&#x27;ll have a chance to use them but seems pretty comprehensive in covering all the basics.
评论 #40786482 未加载
pipeline_peak11 months ago
[6,-2,2,-7].sort()<p>Result : [-2,-7,2,6]<p>Ladies and Gentlemen, the lingua franca of web programming.
评论 #40785650 未加载
评论 #40784890 未加载
评论 #40784972 未加载
评论 #40796344 未加载
twosdai11 months ago
Huh. I might actually start using sets over just simple objects. Never found a great reason to use them before these methods, other than to show off.
评论 #40777358 未加载
评论 #40780558 未加载
评论 #40778212 未加载
评论 #40789224 未加载
评论 #40777169 未加载
mrkeen11 months ago
Damn, in 2024?<p>Do Java next!