Arrays vs. Mappings
Explore the key distinctions between arrays and mappings in Solidity to manage complex data efficiently. Understand their advantages and limitations, learn how to rewrite contracts using mappings, and practice these concepts with Remix IDE to build optimized Ethereum smart contracts.
We'll cover the following...
Arrays and mappings are two ways of storing complex data in Solidity. Each comes with advantages and disadvantages.
Differences between arrays and mappings
We can loop through arrays using for and access an element in an array using the zero-based index of the element. We can’t do these things with mappings. As we’ve learned, arrays in Solidity have push member functions to add, but unlike in JavaScript, there are no filter or find functions. This means that to access a specific element or item in an array in Solidity, we must know its position or index in the array.
One ...