# Easiest and higher value array methods of Dart programming.

As one of the most usable object oriented programming languages, Dart was developed by Google. Which designs for client development and also used to build server and desktop applications as well.

I was starting to learn and use the dart programming language because of the Flutter framework which I used to develop a mobile application for my university mini project. At that time I wasted most of my time for developing some methods without using the inbuilt utilities.After that I followed the documentation and also I was able to find supportive utilities from StackOverflow community. Then I successfully recognized the suitable utilities and optimized my code well.

There are so many inbuilt methods being introduced for easily working with List(Array) in Dart. These are some of the most important 7 methods.

# 1. sort()

order the list according to the given order function.

`var numbers = ['two', 'three', 'four'];// Sort from shortest to longest.numbers.sort((a, b) => a.length.compareTo(b.length));print(numbers);  // [two, four, three]`

Default case is used by compare method

`List<int> nums = [12, 2, -2, -11];nums.sort();print(nums);  // [-11,-2, 2, 12]`

# 2.toSet()

remove duplicates from the list

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

# 3.skip(),take()

Return a new list of skipping or including considerable length.

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

# 4.fold()

Reduce a collection to a single value by given function

`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()

To finding the index of considerable element

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

# 6. contains()

To check whether the given element is include in the list.

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

# 7.forEach()

Applies the given function for each and every elements of the list

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

--

--

Undergraduate in Sabaragamuwa University of Sri Lanaka