Solidity Data Types – How to Convert Between uint256[] and uint256[x] Arrays

arraysdata-typesmemorysolidityuint256

Basically, I want to call a function myfunct(uint256[] memory) but I have a uint256[13]

I have the uint256[13] because I want to temporarily store uint256s in a function, and save memory–not do storage.

Best Answer

I suggest you change the way you built your uint256[13] to use uint256[] memory _value = new uint256[](13); instead. Then you should be able to use myFunc(_value).

If your array does not always contain 13 elements, you can replace 13 with a variable, like so:

uint256 _n = 3;
uint256[] memory _value = new uint256[](_n);
// populate your array
Related Topic