Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Dart

Idiom #254 Replace value in list

Replace all exact occurrences of "foo" with "bar" in the string list x

x = x.map((e) => e == 'foo' ? 'bar' : e).toList();
for (var i = 0; i < x.length; i++) {
  if (x[i] == 'foo') x[i] = 'bar';
}
(replace {"foo" "bar"} x)

New implementation...