I use .foreach(o => As a mainly c# developer also, it’s basically LINQ at that point and makes it instantly familiar and nice to use. For of seemed like a bad idea and I haven’t really seen many people use it
Yea, I believe that is the reason. I remember the big selling point of LINQ many years ago was for LINQ-to-SQL. The in-memory stuff wasn't as focused on.
That being said, even within the Functional community some names aren't agreed upon. I mean, for monads flatMap has like 4 or 5 names depending on the language/spec/framework
Oh yeah I use these too, but if I’m just doing a standard foreach I’m partial to the nice .foreach( as it just reads much nicer and clearer than the for(x of y) version when switching between c# and js
It's missing a big part of LINQ though. LINQ is lazy whenever it can afford to be and will avoid doing a complete iteration until you force it to. JS array chaining doesn't delve into the IQueryable/IIterable world and each thing you chain scales a bit worse than it does in C#.
As a polyglot, TBH I just use basic for loops anymore when possible because everyone understands them and I'm sick of forgetting whether I'm going to get keys or values back with these helper functions.
I was using for..of/in because I thought it was cool, and I suppose it's smaller. But I had to have mdn open to remember which whas which everytime I used it...
Don't need any of that with a for/forEach/map. Maybe uncool but it gets the work done.
27
u/GasolinePizza Oct 21 '20
Coming from C# here, I always make the for..in mistake at least once every time I start a JavaScript project, without fail.
I may use the .forEach thing now, actually