Hacker News new | past | comments | ask | show | jobs | submit | saranshk's comments login

they have an experimental implementation but it is not stable according to them. You can read more about it here: https://bugzilla.mozilla.org/show_bug.cgi?id=418039


agreed, though I doubt there's anything we can do about it.


In F# we call it 'collect' instead, partially for this reason.


When I tried to come up with better name for flatMap I got gather.

So maybe collect is a better idea.


there have been a lot of those added to the ES spec lately and a lot more coming soon. So it is always good to check MDN because I usually end up learning something new mostly.


added this to the post as well, a place where there is an array inside an array of objects and you want all those. For example, if we want to extract all roles from the array:

[ { name: "Saransh Kataria" , roles: ['system-admin', 'developer'] }, { name: "Wisdom Geek" , roles: ['basic'] }, ].flatMap(x => x.roles);

// Output => ["admin", "system-admin", "developer"]


wouldn't the output be ['basic', 'system-admin', 'developer'] rather than array[0] being 'admin'?


You are right that it should be 'basic', not 'admin'. But the order should be 'system-admin', 'developer', and finally 'basic'.


you are right, I was trying to format it for HN but somehow screwed up copy pasting, though it'd be ["system-admin", "developer", "basic"] and not ['basic', 'system-admin', 'developer']


while there is nothing wrong with that, it's always good to have these things built-in as native functions instead.


probably would not have been written then, it is a stage 3 proposal but should be merged in hopefully soon.


all of lodash features would probably become a native thing soon enough


groupByToMap would be useful in that case as pointed out in another comment. Updated the post with that.


updated the post with groupByToMap, Thanks for pointing that out.


Our instances started working again, so seems to be fixed


Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: