List (Array) in Dart

Arrays in Dart compared to other programming languages like PHP or Node.js have some differences in terminology, usage, and features. Let's discuss these differences in detail:
Terminology
Dart: Dart does not use the term "array". Instead, Dart uses the term "List". A List in Dart is an indexed and mutable collection.
PHP: PHP uses the term "array" for a data structure that can store elements of different types. PHP arrays can act as indexed arrays, associative arrays, or multidimensional arrays.
Node.js (JavaScript): JavaScript, which is used in Node.js, uses the term "array". An array in JavaScript is a dynamic-length object that can store elements of different types.
Declaration and Initialization
Dart
void main() {
List<int> numbers = [1, 2, 3, 4, 5];
print(numbers); // Output: [1, 2, 3, 4, 5]
}
PHP
<?php
$numbers = array(1, 2, 3, 4, 5);
print_r($numbers); // Output: Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 )
?>
JavaScript (Node.js)
let numbers = [1, 2, 3, 4, 5];
console.log(numbers); // Output: [1, 2, 3, 4, 5]
Adding Elements
Dart
void main() {
List<int> numbers = [1, 2, 3];
numbers.add(4);
print(numbers); // Output: [1, 2, 3, 4]
}
PHP
<?php
$numbers = array(1, 2, 3);
$numbers[] = 4;
print_r($numbers); // Output: Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 )
?>
JavaScript (Node.js)
let numbers = [1, 2, 3];
numbers.push(4);
console.log(numbers); // Output: [1, 2, 3, 4]
Removing Elements
Dart
void main() {
List<int> numbers = [1, 2, 3, 4];
numbers.removeAt(2);
print(numbers); // Output: [1, 2, 4]
}
PHP
<?php
$numbers = array(1, 2, 3, 4);
unset($numbers[2]);
$numbers = array_values($numbers); // Reindex array
print_r($numbers); // Output: Array ( [0] => 1 [1] => 2 [2] => 4 )
?>
JavaScript (Node.js)
let numbers = [1, 2, 3, 4];
numbers.splice(2, 1);
console.log(numbers); // Output: [1, 2, 4]
Special Features
Dart
Typed Lists: Dart allows you to declare Lists with a specific type, such as
List<int>orList<String>, which provides type safety at compile time.Built-in Methods: Dart provides many built-in methods like
add,remove,insert,sort,map,reduce, and many more that make List manipulation easier.
PHP
Flexible Arrays: PHP arrays are highly flexible and can be used as indexed arrays, associative arrays, or multidimensional arrays.
Array Functions: PHP provides many built-in array functions such as
array_push,array_pop,array_merge,array_diff,array_map, and others.
JavaScript (Node.js)
Dynamic Typing: JavaScript arrays are dynamic and can store elements of different types.
Array Methods: JavaScript provides many modern array methods such as
push,pop,shift,unshift,map,filter,reduce, and more for advanced data manipulation.
Conclusion
Dart: Uses typed Lists, provides many built-in methods, and offers type safety at compile time.
PHP: Uses highly flexible arrays that support various types of arrays and comes with numerous built-in array functions.
JavaScript (Node.js): Uses dynamic arrays that can store elements of different types and offers many modern array methods for advanced data manipulation.


![[Indonesian] Memahami Wiki AW Non-Commercial License 1.0](/_next/image?url=https%3A%2F%2Fcdn.hashnode.com%2Fuploads%2Fcovers%2F6608de5cd660c76b8626061d%2Ff2bf3812-7079-4c4f-a6f9-fe2ba1c0aa06.png&w=3840&q=75)


![[Indonesian] 13 Organ HODi (Hybrid Omnichannel Distribution)](/_next/image?url=https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1753044716865%2F77ddf777-bac7-4d0b-882b-1273ddaf2adf.png&w=3840&q=75)