Answers for "solidity return array"

1

Solidity array

// 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();
}
Posted by: Guest on May-04-2022
0

solidity array

uint size = 3;
uint balance[] = new uint[](size);
Posted by: Guest on February-25-2022
0

solidity return array

function myFunc() public returns (uint8[5]) {
	return [1, 2, 3, 4, 5]
}
Posted by: Guest on April-22-2022

Browse Popular Code Answers by Language