4 ms·
For kicks, here's Dart versions of those: Reducing boilerplate for loop code: var index = 0; for (var el in arr) { el.doThing(index++); } D
by munificent 13y ago
For kicks, here's Dart versions of those:
Reducing boilerplate for loop code:
var index = 0;
for (var el in arr) {
el.doThing(index++);
}
Dart hasn't really optimizing for iterating over a collection with indices since we don't find that very common in real-world code.
Better iteration over objects:
obj.forEach((k, v) => print("$k is $v"));
Here, obj is a map data structure, not a random object since Dart distinguishes objects and data structures.
Default function params:
foobar([foo = "default", bar = "shmefault") {
// Go on...
}
String interpolation:
str = "There are $num ${item}s available for \$$price each"
- lowboy 13y agoDoes Dart compile that for loop down to a regular for loop instead of the JS for..in loop? Or are there any safeguards against someone adding a property to an array (not that they should)? a = [1,2,3]; a.prop = "oops"; for(el in a) console.log(el); // > 0 // > 1 // > 2 // > oops