How to delete an element of an array in an Ethereum contract?

2

I am wondering - is it possible to delete a single element of an array in Ethereum without having to create a new array and copying the entire array? Reading some of the documentation, I can't seem to find any good way of doing this.

ThePiachu

Posted 2015-06-22T03:05:32.813

Reputation: 41 594

Answers

2

If you want the operation of removing an element from a list to be efficient (i.e. without having to copy the list), you have to use a different data structure, e.g. a linked list or a mapping with a reverse index. Note that delete arr[ind] does not rearrange the array but only resets the array element.

chriseth

Posted 2015-06-22T03:05:32.813

Reputation: 246

4

Refer to the documentation:

delete myArray[arrayIndex];

cryptoInnovator

Posted 2015-06-22T03:05:32.813

Reputation: 41