xxxxxxxxxx
function myFunc() public returns (uint8[5]) {
return [1, 2, 3, 4, 5]
}
xxxxxxxxxx
// Create array
address[] addresses
uint256[] myArray
// Add to array
function add() internal {
myArray.push(123);
}
// Remove from array
function removeUnordered() internal {
myArray[index] = myArray[myArray.length - 1];
myArray.pop();
}
function removeOrdered() internal {
// WARN: This unbounded for loop is an anti-pattern
for(uint256 i = index; i < myArray.length-1; i++){
myArray[i] = myArray[i+1];
}
myArray.pop();
}
xxxxxxxxxx
pragma solidity ^0.6.0;
contract samplyArray {
uint[] public myArray; //this is a dynamic array of type uint
uint[] public myArray2 = [1, 2, 3]; //this is a dynamic array with 1, 2 and 3 as default values
uint[10] public myFixedSizeArray; //this is a fixed size array of type uint
}