I have function, that goes to return and delete last element from array, but if I delete this element, function could return null value

function poll(Queue storage _queue) public returns(Job job) {
    require(_queue.length - 1 < cursorPosition);
    // there should be element deleting
    return (_queue.jobArray[cursorPosition - 1]);
  • store the element in some temorary variable, delete it and return the temporary variable? have you tried that ? Commented Mar 2, 2018 at 10:03
  • right! Thank you. Could you make an answer, so I can check it as correct
    – Koroqe
    Commented Mar 2, 2018 at 10:10

1 Answer 1


There is no cost-effective way to do this, as the delete type behave like an assignation to the default value, thus returning a zero-like value.

As @Med Mansour told you above, store the value in a variable and then return said variable.

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.