0

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
  • 2
    See ethereum.stackexchange.com/questions/40312/…
    – ivicaa
    Commented Jan 27, 2019 at 8:01
  • 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. Commented Jan 27, 2019 at 22:19

1 Answer 1

2

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.

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.