I want to create a fixed array(w*h
), w*h
is the maximum size, and when the condition meet(checkOwner(_temp) == msg.sender
), the data(_temp
) will store into the _array
.
My question is if only few conditions meet, _array.length
will still return w*h
.
How do I let _array
return the actual length of the value?
function Test(uint256 w, uint256 h) external {
uint256[] memory _array = new uint[](w*h);
uint _count = 0;
for(uint j = 0; j<h; j++){
uint256 _temp = ..... // do the calculation
// Call checkOwner function to check the owner
if(checkOwner(_temp) == msg.sender){
_array[_count] = _temp;
_count ++;
}
}
if(_array.length == w*h){
....
}
}