Solidity Remove From Array

[Solved] Solidity Remove From Array | Solidity - Code Explorer | yomemimo.com
Question : solidity remove from array

Answered by : delightful-dotterel-aa0jn6ob5xhc

// If you don't care about ordering
arr[removeIndex] = arr[arr.length - 1];
arr.pop();
// Perserves order
for (uint i = removeIndex; i < arr.length - 1; i++) {	arr[i] = arr[i+1];
}
arr.pop();

Source : | Last Update : Thu, 07 Oct 21

Question : Solidity remove from array

Answered by : jos-wigchert

// 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();
}

Source : | Last Update : Wed, 11 May 22

Answers related to solidity remove from array

Code Explorer Popular Question For Solidity