Web3.js: Return array in methods.myMethod.call

Created on 4 Mar 2019  路  3Comments  路  Source: ChainSafe/web3.js

Expected behavior

I'm trying to get an array of Numbers from this function:

function getTimes() public view returns (uint[] memory) {
    return times;
}

...Calling the function via web3 like this:

ContractInstance.methods.getTimes().call().then(result => {
    console.log(result);        
})

..my output is a comma separeted string: 1551744000,1551657600
In order to get an array of Numbers I have to modify the String like this:

var array = result.split(',').map(str => {return Number(str)})

Now I'm getting the required array of Numbers:

[1551744000,1551657600]

I'm asking myself if this is the right way. Am I missing something? Thanks for any help.

Versions

solidity: ^0.5.0;
web3: 1.0.0-beta.47

bug

All 3 comments

Thanks for creating this issue! Could you please add the version of Web3.js you are using?

Yes, of course. I'm using solidity: ^0.5.0 and web3: 1.0.0-beta.47

Just found out, the issue does not consist with [email protected].

Was this page helpful?
0 / 5 - 0 ratings