What is the use of -1 in instructorAccts.push(_address) -1?

function setInstructor(address _address, uint _age, string _fName, string _lName) public {
    var instructor = instructors[_address];        
    instructor.age = _age;
    instructor.fName = _fName;
    instructor.lName = _lName;

    instructorAccts.push(_address) -1;
  • 2
  • My guess is -1 was blindly copied from another example. push()-1 corresponds to the row in the array occupied by the appended element. As @goodvibration points out, the result of this work isn't assigned to anything (e.g. uint position = array.push(value) -1) so the extra work is pointless. – Rob Hitchens Jan 27 '19 at 22:19

The expression instructorAccts.push(_address) equals to the length of the instructorAccts array after pushing the _address item into it.

The expression instructorAccts.push(_address) - 1 equals to the length of the instructorAccts array before pushing the _address item into it.

In your example, since this value is not stored or used in any manner, this expression has no effect.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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