1
pragma solidity ^0.4.0;

// delete an array of names
contract ArrayDelete {
string[] names;

function main() returns (string[]) {
   names.push("Jones");
   names.push("Ama");
   names.push("Emeka");
   names.push("Owo");
   names.push("Lulu");

   delete names[0];
   return names;
 }
}

Any ideas why this error occurs? None of the answers on similar questions was helpful in fixing this.

1 Answer 1

7

You can't return a dynamic array of dynamic arrays from a Solidity function. From the Solidity docs:

Is it possible to return an array of strings (string[]) from a Solidity function?

Not yet, as this requires two levels of dynamic arrays (string is a dynamic array itself).

3
  • 5
    "You can't return a dynamic array from a Solidity function." This is inaccurate. You can return a dynamic array, but you can't return a dynamic array of dynamic arrays. (string is a dynamic array.) So a return type of uint256[] is fine but not string[].
    – user19510
    Commented Jan 26, 2018 at 21:51
  • 1
    So anything method that has to deal with something similar will have make use of numbers? What's the work around for doing this with strings ? Commented Jan 26, 2018 at 21:52
  • It's 2022 and this is no longer a problem, thanks to ABIEncoderV2 which is enabled by default since Solidity v0.8. You can safely return a dynamic array of dynamic arrays, such as string[]. Commented Jul 14, 2022 at 9:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.