Comments (16)
Yet another great post DP with new info and clear exp !!
Thanks @kishoreandra!
from dmitripavlutin.com-comments.
The benefit of Map is that it accepts any data type as a key, but the plain object is limited to strings only.
As I know, a plain object is limited to strings and symbols, am I right?
Strictly, you're right that strings and symbols are keys in plain objects. But I almost always use strings as keys.
But I updated the post per your suggestion. Thanks @ipovos.
from dmitripavlutin.com-comments.
This article should be updated because now they rename it to Object.groupBy
: https://github.com/tc39/proposal-array-grouping
from dmitripavlutin.com-comments.
@aralroca Thanks. Post updated.
from dmitripavlutin.com-comments.
Yet another great post DP with new info and clear exp !!
from dmitripavlutin.com-comments.
The benefit of Map is that it accepts any data type as a key, but the plain object is limited to strings only.
As I know, a plain object is limited to strings and symbols, am I right?
from dmitripavlutin.com-comments.
Second time google directed me to your useful information, thanks for sharing and for this blog.
Alex
from dmitripavlutin.com-comments.
appreciate the post,
I have used node 16 and node 18 to used groupBy method on an arry and both time it throw an error saying products.groupBy is not a function
any idea? thanks
from dmitripavlutin.com-comments.
Hey @yusuf963, please have a look at this issue (on group for group by) and it should be used carefully until it ships and official by ES committee... https://github.com/tc39/proposal-array-grouping#why-group-and-not-groupby
from dmitripavlutin.com-comments.
Couldn't your groupToMap example just have used group() seeing as it's using strings as keys? I would find it more instructive if it had returned something that actually needed to be a Map
from dmitripavlutin.com-comments.
Couldn't your groupToMap example just have used group() seeing as it's using strings as keys? I would find it more instructive if it had returned something that actually needed to be a Map
@o-t-w Feel free to create a Pull Request for this post with a more meaningful example. 🎸
from dmitripavlutin.com-comments.
Is there a way to use this and show the output in an
from dmitripavlutin.com-comments.
Quick question, how do I map out the grouped data?
from dmitripavlutin.com-comments.
Quick question, how do I map out the grouped data?
@o-david Can you give more details what you want to achieve?
from dmitripavlutin.com-comments.
Made a test example with Object.groupBy and two Array.reduce functions, one with a body like in your article, and another reduce slightly optimized:
https://jsperf.app/raxofi
It appears that in Chrome 118 Object.groupBy is performing slightly slower than optimized Array.reduce, while unoptimezed Array.reduce is 1/3 slower.
Optimization is done on resulting grouping object updating, originally you have to access group[category] THREE times:
group[category] = group[category] ?? [];
group[category].push(product);
Instead you can write:
group[category]?.push(product) ?? ( group[category] = [ product ] );
from dmitripavlutin.com-comments.
Now is there any way to make it work with TypeScript?
I tried adding the following option to tsconfig.json
but it still reports the error Property 'groupBy' does not exist on type 'ObjectConstructor'.ts(2339)
.
"target": "esnext",
"lib": ["ESNext"],
from dmitripavlutin.com-comments.
Related Issues (20)
- react-usememo-hook/ HOT 12
- javascript-json-modules/ HOT 7
- javascript-import-meta/ HOT 3
- javascript-array-flatmap/ HOT 23
- interface-vs-implementation/ HOT 11
- vue-next-tick/ HOT 4
- props-destructure-vue-composition/ HOT 7
- ref-reactive-differences-vue/ HOT 5
- environment-variables-javascript/ HOT 3
- ref-in-vue/ HOT 1
- typescript-function-type/ HOT 5
- vue-v-model-form-inputs/ HOT 2
- react-forwardref/ HOT 4
- javascript-enum/ HOT 19
- react-comments/ HOT 8
- typescript-record/ HOT 10
- screen-window-page-sizes/ HOT 3
- javascript-pure-function/ HOT 1
- Great article
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dmitripavlutin.com-comments.