How to properly delete the first element in an array?

by user3332558   Last Updated December 06, 2018 14:28 PM

Is it possible to delete the first element of an array without shifting all elements later?

My guess is that I can remember the index of the 'current first element', like so:

uint[] public myArray;
uint firstElement;
myArray.push(3);
myArray.push(6);
myArray.push(10);
delete myArray[firstElement];
firstElement++;

but, is there a convention or something built in for this?

Tags : solidity arrays


Related Questions


Updated July 02, 2017 23:28 PM

Updated August 09, 2017 17:28 PM

Updated August 10, 2017 08:28 AM

Updated August 08, 2017 14:28 PM

Updated January 16, 2018 18:28 PM