0

I am trying to log length of an array inside a struct.

struct Student{
    bytes32 PatietRecordHash;
    bool isExists;
    bytes32[] ReportIpfsHash;
}
event LogStudentReportLength(uint noOfReports);
function addStudentReport(bytes32 _StudentId,bytes32 _ReportIpfsHash)public returns(bool){
    require(msg.sender == systemAdmin);

   emit LogStudentReportLength(Students[_StudentId].ReportIpfsHash.push(_ReportIpfsHash));
   uint length= getNoOfLabReports(_StudentId);
   Students[_StudentId].ReportIpfsHash[length-1]=_ReportIpfsHash;
   emit LogNewStudentLabReport(true,_ReportIpfsHash,patients[_patientId].ReportIpfsHash.length);
   return true;
}

I am getting result as following in the browser console.

Object { s: 1, e: 0, c: (1) […] }

However I am expecting a length of array.

1

That is your length of the array but it's represented as a BigNumber Object because javascript can't handle big numbers.

More information about how you handle them can be found here (aka .toString() and convert them to a number :p )

Hope it helps :D

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