The pop() functions works correctly for normal arrays and mappings.
Based on: How to delete an element at a certain index in an array?
When I try to pop() an array of a mapping not work.
Any alternative to remove the gaps?
pragma solidity ^0.8.0;
// SPDX-License-Identifier:
contract test {
mapping (address => uint[]) MyMap;
constructor(){
MyMap[msg.sender].push(0);
MyMap[msg.sender].push(1);
MyMap[msg.sender].push(2);
MyMap[msg.sender].push(3);
}
//Set last into [2] //1
MyMap[msg.sender][2] = MyMap[msg.sender][MyMap[msg.sender].length - 1];
//Delete last array position
MyMap[msg.sender].pop(); //This line is the problem...
}