Lists (aka Arrays)
Lists of things are a requirement of any language. Easing developers into the language, Dart sticks close to the expected with lists.
primitives/lists.dart | |
| var muppets = ['The Count', 'Bert', 'Ernie', 'Snuffleupagus']; |
| var primes = [1, 2, 3, 5, 7, 11]; |
| // Indexed from zero |
| muppets[0]; // 'The Count' |
| primes.length; // 6 |
Dart does provide some nice, consistent methods for manipulating lists.
| var muppets = ['The Count', 'Bert', 'Ernie', 'Snuffleupagus']; |
| muppets.setRange(1, 3, ['Kermit', 'Oscar']); |
| // muppets => ['The Count', 'Kermit', 'Oscar', 'Snuffleupagus'] |
| muppets.removeRange(1, 3); |
| // muppets => ['The Count', 'Snuffleupagus']; |
| muppets.addAll(['Elmo', 'Cookie Monster']); ... |
Get Dart 1 for Everyone now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.