- Mastering Ethereum
- Merunas Grincalaitis
- 112字
- 2021-06-24 15:01:05
Arrays
Arrays allow you to store large amounts of the same type of variable in one place. They are used as lists that contain a specific type of information for your smart contracts so that you can store your data in an orderly manner. They can be accessed with a simple for loop by getting the length of them.
You can create arrays of uints, strings, structs, addresses, and pretty much any other type:
uint256[] public myNumbers;
string[] public myTexts;
You can also delete elements from an array with the following keyword:
delete myTexts[2];
You can also use .push() and .pop() to add or remove elements from the array in dynamically-sized arrays.