Arrays
An array is an ordered collection of elements. In Duwa, an array is a type that represents arrays. It is used to represent a list of values.
Rules for arrays:
- All elements in an array must be of the same type.
- Arrays are zero-based, meaning the first element is at index
0
. - The size of an array is dynamic and can be changed at runtime.
- Arrays can be multidimensional.
Syntax
nambala[] x = [1, 2, 3, 4, 5];
Accessing elements
You can access elements of an array using the index. The index starts at 0
.
nambala[] x = [1, 2, 3, 4, 5];
Khonso.lemba(x[0]); // 1
Updating elements
You can update elements of an array using the index.
nambala[] x = [1, 2, 3, 4, 5];
x[0] = 10;
Khonso.lemba(x[0]); // 10
Examples usage
nambala[] x = [1, 2, 3, 4, 5];
Khonso.lemba(x[0]); // 1
Khonso.lemba(x[1]); // 2
Khonso.lemba(x[2]); // 3
Khonso.lemba(x[3]); // 4
Khonso.lemba(x[4]); // 5
Methods
kutalika()→ number
Returns
number
Returns the number of elements in an array.
chotsaKumbuyo()→ any
Returns
any
Removes the last element from an array and returns that element. This method changes the length of the array.
Kankha()→ number
Returns
number
Adds one or more elements to the end of an array and returns the new length of the array.
chotsaKutsogolo()→ any
Returns
any
Removes the first element from an array and returns that element. This method changes the length of the array.