I need help!
Kindly bare with me as I am new to Solidity.
I am trying to use the slice
array method to remove the first element in my array while also decreasing the array length.
I have a function that successful inserts elements into the array.
According to the Array slices documentation, “array slices are only implemented for calldata arrays”, I am not able to fully understand how to use this information in my code, but I keep getting the below error message every time I run the compiler.
The error message seems to be caused by the deleteUser()
function:
Warning: This declaration shadows an existing declaration.
Find below my solidity function:
pragma solidity ^0.8.2;
address[] private userIndex;
function insertUser(address userAddress, string memory userEmail, uint userAge) public returns(uint index)
{
userStructs[userAddress].userEmail = userEmail;
userStructs[userAddress].userAge = userAge;
userIndex.push(userAddress);
userStructs[userAddress].index = userIndex.length -1;
return userIndex.length-1;
}
function getUser(address userAddress) public view returns(string memory userEmail, uint userAge, uint index)
{
return( userStructs[userAddress].userEmail, userStructs[userAddress].userAge, userStructs[userAddress].index);
}
function deleteUser(address userAddress, address[] calldata userIndex) public returns (uint256 length)
{
userIndex[1:];
return userIndex.length;
}
In Remix, running the getUser("0xAb8483F64d9C6d1EcF9b849Ae677dD3315835cb2")
yeilds:
0:string: userEmail [email protected]
1:uint256: userAge 35
2:uint256: index 2
Kindly help me understand how I can use the array slice
to delete the first element in my array in my deleteUser()
function