Easiest and higher value array methods of Dart programming.

1. sort()

var numbers = ['two', 'three', 'four'];
// Sort from shortest to longest.
numbers.sort((a, b) => a.length.compareTo(b.length));
print(numbers); // [two, four, three]
List<int> nums = [12, 2, -2, -11];
nums.sort();
print(nums); // [-11,-2, 2, 12]

2.toSet()

List<int> nums = [13, 2,2,5,9,13,13,-11, -11];
nums.toSet();
print(nums); // [13,2,5,9,-11]

3.skip(),take()

var myList = [13,8, 2,9,12, -11];
var firstThreeOfMyList = myList.take(3)
print(firstThreeOfMyList); // [13, 8, 2]

4.fold()

dynamic fold(var initialValue,
dynamic combine(var previousValue, E element));
List<int> nums = [13, 2, 5,7,-2];//get initial value as 0var sumOfnums = nums.flod(0,(sum,next)=>sum+next);
print(sumOfnums) //[25]

5.indexOf()

var students= ['John', 'Jane' , 'Magi','Nimal','Mala'];
print(students.indexOf('Magi')); // 2

6. contains()

List<int> nums = [13, 2, 5,7,-2];
print(nums.contains(2)) // true
print(nums.contains(9)) //false

7.forEach()

List<int> nums = [13, 2, 5,7,-2];nums.forEach((number)=>print(nums)); // 13 2 5 7 -2

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store