LoginSignup
3
0

More than 3 years have passed since last update.

JSer向け dart配列API

Last updated at Posted at 2020-01-13

List関連の関数
https://api.dart.dev/stable/2.7.0/dart-core/List-class.html

Array.prototype.slice()

start-endの配列を抽出

var testList = [1, 2, 3];
testList.sublist(0,2); // => [1, 2]

Array.prototype.filter()

条件にあうものを抽出

var testList = [1, 2, 3];
testList.where((int item) => item >= 2).toList(); // => [2, 3]

Array.prototype.map()

mapで値を変換して返す

var testList = [1, 2, 3];
testList.map((int item) => Text(item)).toList(); // => [Text("2"), Text("3")]

Array.prototype.every()

全ての条件がtrue であれば true

var testList = [1, 2, 3];
testList.every((int item) => item >= 0); // => true
testList.every((int item) => item >= 2); // => false

Array.prototype.some()

1つの条件がtrueであれば true

var testList = [1, 2, 3];

testList.any((item) => item >= 2); // => true
testList.any((item) => item >= 4); // => false
3
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
0