Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR DART

Dart set list spread operator

/*Dart 2.3 introduced the spread operator (...) and the null-aware spread operator (...?),
which provide a concise way to insert multiple values into a collection.
For example, you can use the spread operator (...) 
to insert all the values of a list into another list:*/
var list = [1, 2, 3];
var list2 = [0, ...list];//var list and values added to list2 wich contains 0 already.
assert(list2.length == 4);

/*If the expression to the right of the spread operator might be null, 
you can avoid exceptions by using a null-aware spread operator (...?):*/
var list;
var list2 = [0, ...?list];
assert(list2.length == 1);
Source by dart.dev #
 
PREVIOUS NEXT
Tagged: #Dart #set #list #spread #operator
ADD COMMENT
Topic
Name
8+8 =